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

Merge pull request #5934 from ErisDS/findall-partial-revert

Revert to using findAll for internal tools
This commit is contained in:
Sebastian Gierlinger 2015-10-11 18:28:18 +02:00
commit debdfa74df
4 changed files with 13 additions and 12 deletions

View file

@ -23,13 +23,13 @@ DataImporter.prototype.loadRoles = function () {
DataImporter.prototype.loadUsers = function () {
var users = {all: {}},
options = _.extend({}, {include: ['roles'], limit: 'all'}, internal);
options = _.extend({}, {include: ['roles']}, internal);
return models.User.findPage(options).then(function (data) {
data.users.forEach(function (user) {
users.all[user.email] = {realId: user.id};
if (user.roles[0] && user.roles[0].name === 'Owner') {
users.owner = user;
return models.User.findAll(options).then(function (_users) {
_users.forEach(function (user) {
users.all[user.get('email')] = {realId: user.get('id')};
if (user.related('roles').toJSON(options)[0] && user.related('roles').toJSON(options)[0].name === 'Owner') {
users.owner = user.toJSON(options);
}
});

View file

@ -187,7 +187,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
/**
* Returns an array of keys permitted in every method's `options` hash.
* Can be overridden and added to by a model's `permittedOptions` method.
* @return {Array} Keys allowed in the `options` hash of every model's method.
* @return {Object} Keys allowed in the `options` hash of every model's method.
*/
permittedOptions: function permittedOptions() {
// terms to whitelist for all methods.
@ -229,6 +229,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
*/
findAll: function findAll(options) {
options = this.filterOptions(options, 'findAll');
options.withRelated = _.union(options.withRelated, options.include);
return this.forge().fetchAll(options).then(function then(result) {
if (options.include) {
_.each(result.models, function each(item) {

View file

@ -44,13 +44,13 @@ models = {
deleteAllContent: function deleteAllContent() {
var self = this;
return self.Post.findPage({limit: 'all'}).then(function then(data) {
return Promise.all(_.map(data.posts, function mapper(post) {
return self.Post.findAll().then(function then(posts) {
return Promise.all(_.map(posts.toJSON(), function mapper(post) {
return self.Post.destroy({id: post.id});
}));
}).then(function () {
return self.Tag.findPage({limit: 'all'}).then(function then(data) {
return Promise.all(_.map(data.tags, function mapper(tag) {
return self.Tag.findAll().then(function then(tags) {
return Promise.all(_.map(tags.toJSON(), function mapper(tag) {
return self.Tag.destroy({id: tag.id});
}));
});

View file

@ -513,7 +513,7 @@ describe('Post Model', function () {
}).catch(done);
});
it.only('can save a draft without setting published_by or published_at', function (done) {
it('can save a draft without setting published_by or published_at', function (done) {
var newPost = testUtils.DataGenerator.forModel.posts[2],
postId;