0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

🐛 Fixed incorrect data returned when using API fields

refs 188de00489

- this fix was incorrect - the function should have been on the
  prototype but I'd moved it over incorrectly into the static class functions
- this commit moves `defaultColumnsToFetch` to the prototype functions
  and reverts the referenced commit back to `this.prototype` as expected
- this wasn't including the custom columns from the `post` model, which
  was causing tests to fail
- pro tip: run tests!
This commit is contained in:
Daniel Lockyer 2021-06-24 13:47:15 +01:00
parent d4a0295792
commit f2ab12bb91
No known key found for this signature in database
GPG key ID: D21186F0B47295AD

View file

@ -5,7 +5,12 @@ const errors = require('@tryghost/errors');
* @param {Bookshelf} Bookshelf
*/
module.exports = function (Bookshelf) {
Bookshelf.Model = Bookshelf.Model.extend({}, {
Bookshelf.Model = Bookshelf.Model.extend({
// When loading an instance, subclasses can specify default to fetch
defaultColumnsToFetch: function defaultColumnsToFetch() {
return [];
}
}, {
/**
* ### Find All
* Fetches all the data for a particular model
@ -69,7 +74,7 @@ module.exports = function (Bookshelf) {
// and append default columns to fetch
if (options.columns) {
options.columns = _.intersection(options.columns, this.prototype.permittedAttributes());
options.columns = _.union(options.columns, this.defaultColumnsToFetch());
options.columns = _.union(options.columns, this.prototype.defaultColumnsToFetch());
}
if (options.order) {
@ -213,11 +218,6 @@ module.exports = function (Bookshelf) {
.then(function then(obj) {
return obj.destroy(options);
});
},
// When loading an instance, subclasses can specify default to fetch
defaultColumnsToFetch: function defaultColumnsToFetch() {
return [];
}
});
};