不要怂,就是干,撸起袖子干!

Commit 053145cd by frlinw Committed by Sushant

refactor(model): remove .all alias (#9975)

1 parent f7585ac0
...@@ -150,11 +150,6 @@ Project.findAll().then(projects => { ...@@ -150,11 +150,6 @@ Project.findAll().then(projects => {
// projects will be an array of all Project instances // projects will be an array of all Project instances
}) })
// also possible:
Project.all().then(projects => {
// projects will be an array of all Project instances
})
// search for specific attributes - hash usage // search for specific attributes - hash usage
Project.findAll({ where: { name: 'A Project' } }).then(projects => { Project.findAll({ where: { name: 'A Project' } }).then(projects => {
// projects will be an array of Project instances with the specified name // projects will be an array of Project instances with the specified name
......
...@@ -1556,10 +1556,6 @@ class Model { ...@@ -1556,10 +1556,6 @@ class Model {
return self; return self;
} }
static all(options) {
return this.findAll(options);
}
/** /**
* Search for multiple instances. * Search for multiple instances.
* *
......
...@@ -55,12 +55,12 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -55,12 +55,12 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this.t = t; this.t = t;
return article.setLabels([label], { transaction: t }); return article.setLabels([label], { transaction: t });
}).then(function() { }).then(function() {
return this.Article.all({ transaction: this.t }); return this.Article.findAll({ transaction: this.t });
}).then(articles => { }).then(articles => {
return articles[0].getLabels(); return articles[0].getLabels();
}).then(function(labels) { }).then(function(labels) {
expect(labels).to.have.length(0); expect(labels).to.have.length(0);
return this.Article.all({ transaction: this.t }); return this.Article.findAll({ transaction: this.t });
}).then(function(articles) { }).then(function(articles) {
return articles[0].getLabels({ transaction: this.t }); return articles[0].getLabels({ transaction: this.t });
}).then(function(labels) { }).then(function(labels) {
......
...@@ -77,10 +77,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -77,10 +77,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
return Group.create({ name: 'bar' }).then(group => { return Group.create({ name: 'bar' }).then(group => {
return sequelize.transaction().then(t => { return sequelize.transaction().then(t => {
return group.setUser(user, { transaction: t }).then(() => { return group.setUser(user, { transaction: t }).then(() => {
return Group.all().then(groups => { return Group.findAll().then(groups => {
return groups[0].getUser().then(associatedUser => { return groups[0].getUser().then(associatedUser => {
expect(associatedUser).to.be.null; expect(associatedUser).to.be.null;
return Group.all({ transaction: t }).then(groups => { return Group.findAll({ transaction: t }).then(groups => {
return groups[0].getUser({ transaction: t }).then(associatedUser => { return groups[0].getUser({ transaction: t }).then(associatedUser => {
expect(associatedUser).to.be.not.null; expect(associatedUser).to.be.not.null;
return t.rollback(); return t.rollback();
...@@ -207,7 +207,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -207,7 +207,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
return Group.create({ name: 'bar' }).then(group => { return Group.create({ name: 'bar' }).then(group => {
return sequelize.transaction().then(t => { return sequelize.transaction().then(t => {
return group.setUser(user, { transaction: t }).then(() => { return group.setUser(user, { transaction: t }).then(() => {
return Group.all().then(groups => { return Group.findAll().then(groups => {
return groups[0].getUser().then(associatedUser => { return groups[0].getUser().then(associatedUser => {
expect(associatedUser).to.be.null; expect(associatedUser).to.be.null;
return t.rollback(); return t.rollback();
......
...@@ -488,13 +488,13 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -488,13 +488,13 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
t = _t; t = _t;
return article.setLabels([label], { transaction: t }); return article.setLabels([label], { transaction: t });
}).then(() => { }).then(() => {
return Article.all({ transaction: t }); return Article.findAll({ transaction: t });
}).then(articles => { }).then(articles => {
return articles[0].hasLabel(label).then(hasLabel => { return articles[0].hasLabel(label).then(hasLabel => {
expect(hasLabel).to.be.false; expect(hasLabel).to.be.false;
}); });
}).then(() => { }).then(() => {
return Article.all({ transaction: t }); return Article.findAll({ transaction: t });
}).then(articles => { }).then(articles => {
return articles[0].hasLabel(label, { transaction: t }).then(hasLabel => { return articles[0].hasLabel(label, { transaction: t }).then(hasLabel => {
expect(hasLabel).to.be.true; expect(hasLabel).to.be.true;
...@@ -594,7 +594,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -594,7 +594,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
this.t = t; this.t = t;
return this.article.setLabels([this.label], { transaction: t }); return this.article.setLabels([this.label], { transaction: t });
}).then(function() { }).then(function() {
return this.Article.all({ transaction: this.t }); return this.Article.findAll({ transaction: this.t });
}).then(function(articles) { }).then(function(articles) {
return Promise.all([ return Promise.all([
articles[0].hasLabels([this.label]), articles[0].hasLabels([this.label]),
......
...@@ -76,10 +76,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -76,10 +76,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
return Group.create({ name: 'bar' }).then(group => { return Group.create({ name: 'bar' }).then(group => {
return sequelize.transaction().then(t => { return sequelize.transaction().then(t => {
return group.setUser(user, { transaction: t }).then(() => { return group.setUser(user, { transaction: t }).then(() => {
return Group.all().then(groups => { return Group.findAll().then(groups => {
return groups[0].getUser().then(associatedUser => { return groups[0].getUser().then(associatedUser => {
expect(associatedUser).to.be.null; expect(associatedUser).to.be.null;
return Group.all({ transaction: t }).then(groups => { return Group.findAll({ transaction: t }).then(groups => {
return groups[0].getUser({ transaction: t }).then(associatedUser => { return groups[0].getUser({ transaction: t }).then(associatedUser => {
expect(associatedUser).not.to.be.null; expect(associatedUser).not.to.be.null;
expect(associatedUser.id).to.equal(user.id); expect(associatedUser.id).to.equal(user.id);
...@@ -140,7 +140,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -140,7 +140,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
]); ]);
}).spread((fakeUser, user, group) => { }).spread((fakeUser, user, group) => {
return group.setUser(user).then(() => { return group.setUser(user).then(() => {
return Group.all().then(groups => { return Group.findAll().then(groups => {
return groups[0].getUser().then(associatedUser => { return groups[0].getUser().then(associatedUser => {
expect(associatedUser).not.to.be.null; expect(associatedUser).not.to.be.null;
expect(associatedUser.id).to.equal(user.id); expect(associatedUser.id).to.equal(user.id);
...@@ -174,7 +174,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -174,7 +174,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
return Group.create({ name: 'bar' }).then(group => { return Group.create({ name: 'bar' }).then(group => {
return sequelize.transaction().then(t => { return sequelize.transaction().then(t => {
return group.setUser(user, { transaction: t }).then(() => { return group.setUser(user, { transaction: t }).then(() => {
return Group.all().then(groups => { return Group.findAll().then(groups => {
return groups[0].getUser().then(associatedUser => { return groups[0].getUser().then(associatedUser => {
expect(associatedUser).to.be.null; expect(associatedUser).to.be.null;
return t.rollback(); return t.rollback();
...@@ -365,10 +365,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -365,10 +365,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
return User.create({ username: 'bob' }).then(user => { return User.create({ username: 'bob' }).then(user => {
return sequelize.transaction().then(t => { return sequelize.transaction().then(t => {
return user.createGroup({ name: 'testgroup' }, { transaction: t }).then(() => { return user.createGroup({ name: 'testgroup' }, { transaction: t }).then(() => {
return User.all().then(users => { return User.findAll().then(users => {
return users[0].getGroup().then(group => { return users[0].getGroup().then(group => {
expect(group).to.be.null; expect(group).to.be.null;
return User.all({ transaction: t }).then(users => { return User.findAll({ transaction: t }).then(users => {
return users[0].getGroup({ transaction: t }).then(group => { return users[0].getGroup({ transaction: t }).then(group => {
expect(group).to.be.not.null; expect(group).to.be.not.null;
return t.rollback(); return t.rollback();
......
...@@ -73,7 +73,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -73,7 +73,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be able to use a defaultScope if declared', function() { it('should be able to use a defaultScope if declared', function() {
return this.ScopeMe.all().then(users => { return this.ScopeMe.findAll().then(users => {
expect(users).to.have.length(2); expect(users).to.have.length(2);
expect([10, 5].indexOf(users[0].access_level) !== -1).to.be.true; expect([10, 5].indexOf(users[0].access_level) !== -1).to.be.true;
expect([10, 5].indexOf(users[1].access_level) !== -1).to.be.true; expect([10, 5].indexOf(users[1].access_level) !== -1).to.be.true;
......
...@@ -85,7 +85,7 @@ if (current.dialect.supports.transactions) { ...@@ -85,7 +85,7 @@ if (current.dialect.supports.transactions) {
return t.commit(); return t.commit();
}); });
}).then(function() { }).then(function() {
return this.User.all(); return this.User.findAll();
}).then(users => { }).then(users => {
expect(users.length).to.equal(1); expect(users.length).to.equal(1);
expect(users[0].name).to.equal('foo'); expect(users[0].name).to.equal('foo');
......
...@@ -353,7 +353,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -353,7 +353,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
describe('findAll', () => { describe('findAll', () => {
it('should allow $in', () => { it('should allow $in', () => {
return expect(User.all({ return expect(User.findAll({
where: { where: {
name: { name: {
[Op.like]: { [Op.like]: {
...@@ -365,7 +365,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -365,7 +365,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
it('should allow $like for uuid', () => { it('should allow $like for uuid', () => {
return expect(User.all({ return expect(User.findAll({
where: { where: {
uid: { uid: {
[Op.like]: '12345678%' [Op.like]: '12345678%'
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!