mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Removed defaultColumnsToFetch from models (#11010)
no-issue * Removed redundant options from permittedOptions The column option is already permitted at the Base model level. * Remove defaultColumnsToFetch from Base model * Removed defaultColumnsToFetch from Post model
This commit is contained in:
parent
80a79abff5
commit
45e971b63e
2 changed files with 2 additions and 40 deletions
|
@ -160,11 +160,6 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
|||
return _.keys(schema.tables[this.tableName]);
|
||||
},
|
||||
|
||||
// When loading an instance, subclasses can specify default to fetch
|
||||
defaultColumnsToFetch: function defaultColumnsToFetch() {
|
||||
return [];
|
||||
},
|
||||
|
||||
/**
|
||||
* @NOTE
|
||||
* We have to remember the `_previousAttributes` attributes, because when destroying resources
|
||||
|
@ -883,7 +878,6 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
|||
// and append default columns to fetch
|
||||
if (options.columns) {
|
||||
options.columns = _.intersection(options.columns, this.prototype.permittedAttributes());
|
||||
options.columns = _.union(options.columns, this.prototype.defaultColumnsToFetch());
|
||||
}
|
||||
|
||||
if (options.order) {
|
||||
|
|
|
@ -513,38 +513,6 @@ Post = ghostBookshelf.Model.extend({
|
|||
return this.hasMany('MobiledocRevision', 'post_id');
|
||||
},
|
||||
|
||||
/**
|
||||
* @NOTE:
|
||||
* If you are requesting models with `columns`, you try to only receive some fields of the model/s.
|
||||
* But the model layer is complex and needs specific fields in specific situations.
|
||||
*
|
||||
* ### url generation was removed but default columns need to be checked before removal
|
||||
* - @TODO: with dynamic routing, we no longer need default columns to fetch
|
||||
* - because with static routing Ghost generated the url on runtime and needed the following attributes:
|
||||
* - `slug`: /:slug/
|
||||
* - `published_at`: /:year/:slug
|
||||
* - `author_id`: /:author/:slug, /:primary_author/:slug
|
||||
* - now, the UrlService pre-generates urls based on the resources
|
||||
* - you can ask `urlService.getUrlByResourceId(post.id)`
|
||||
*
|
||||
* ### events
|
||||
* - you call `findAll` with `columns: id`
|
||||
* - then you trigger `post.save()` on the response
|
||||
* - bookshelf events (`onSaving`) and model events (`emitChange`) are triggered
|
||||
* - but you only fetched the id column, this will trouble (!), because the event hooks require more
|
||||
* data than just the id
|
||||
* - @TODO: we need to disallow this (!)
|
||||
* - you should use `models.Post.edit(..)`
|
||||
* - this disallows using the `columns` option
|
||||
* - same for destroy - you should use `models.Post.destroy(...)`
|
||||
*
|
||||
* @IMPORTANT: This fn should **never** be used when updating models (models.Post.edit)!
|
||||
* Because the events for updating a resource require most of the fields.
|
||||
* This is protected by the fn `permittedOptions`.
|
||||
*/
|
||||
defaultColumnsToFetch: function defaultColumnsToFetch() {
|
||||
return ['id', 'published_at', 'slug', 'author_id'];
|
||||
},
|
||||
/**
|
||||
* If the `formats` option is not used, we return `html` be default.
|
||||
* Otherwise we return what is requested e.g. `?formats=mobiledoc,plaintext`
|
||||
|
@ -709,9 +677,9 @@ Post = ghostBookshelf.Model.extend({
|
|||
// whitelists for the `options` hash argument on methods, by method name.
|
||||
// these are the only options that can be passed to Bookshelf / Knex.
|
||||
validOptions = {
|
||||
findOne: ['columns', 'importing', 'withRelated', 'require', 'filter'],
|
||||
findOne: ['importing', 'withRelated', 'require', 'filter'],
|
||||
findPage: ['status', 'staticPages'],
|
||||
findAll: ['columns', 'filter'],
|
||||
findAll: ['filter'],
|
||||
destroy: ['destroyAll', 'destroyBy'],
|
||||
edit: ['filter']
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue