Skip to content

Commit

Permalink
Revert to using findAll for internal tools
Browse files Browse the repository at this point in the history
refs #5909, #4577

- removes accidental '.only' which was hiding issues with the findAll changes
- deleteAllContent and importer still need to use a hard 'findAll' as findPage({limit: 'all'}) doesn't have the same behaviour
  • Loading branch information
ErisDS committed Oct 10, 2015
1 parent 4c1828c commit 0764c77
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions core/server/data/import/data-importer.js
Expand Up @@ -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);
}
});

Expand Down
3 changes: 2 additions & 1 deletion core/server/models/base/index.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions core/server/models/index.js
Expand Up @@ -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});
}));
});
Expand Down
2 changes: 1 addition & 1 deletion core/test/integration/model/model_posts_spec.js
Expand Up @@ -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;

Expand Down

0 comments on commit 0764c77

Please sign in to comment.