0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Moved setId function to Bookshelf events plugin

no issue

- `setId` is only used within the `events` plugin and it makes sense to
  keep code together
- we don't lose anything by putting it here, but it should make it
  easier to test in the future
This commit is contained in:
Daniel Lockyer 2021-06-17 16:51:25 +01:00
parent 5b66933981
commit 0830bcb74e
No known key found for this signature in database
GPG key ID: D21186F0B47295AD
2 changed files with 9 additions and 9 deletions

View file

@ -7,7 +7,6 @@
// All other parts of Ghost, including the frontend & admin UI are only allowed to access data via the API.
const moment = require('moment');
const ObjectId = require('bson-objectid');
const schema = require('../../data/schema');
const ghostBookshelf = require('./bookshelf');
@ -51,14 +50,6 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
return moment(this.get(attr)).diff(moment(this.previous(attr))) !== 0;
},
/**
* we auto generate a GUID for each resource
* no auto increment
*/
setId: function setId() {
this.set('id', ObjectId().toHexString());
},
wasChanged() {
/**
* @NOTE:

View file

@ -1,5 +1,6 @@
const _ = require('lodash');
const debug = require('@tryghost/debug')('models:base:model-events');
const ObjectId = require('bson-objectid');
const events = require('../../../lib/common/events');
const schema = require('../../../data/schema');
@ -31,6 +32,14 @@ module.exports = function (Bookshelf) {
this.on('saved', this.onSaved);
},
/**
* we auto generate a GUID for each resource
* no auto increment
*/
setId: function setId() {
this.set('id', ObjectId().toHexString());
},
/**
* @NOTE
* We have to remember the `_previousAttributes` attributes, because when destroying resources