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

Commit dad03289 by Kevin Mannix

updated docs and tests for issues #5031 and #5489

1 parent 16b39c61
......@@ -123,6 +123,7 @@ $gte: 6, // >= 6
$lt: 10, // < 10
$lte: 10, // <= 10
$ne: 20, // != 20
$not: true, // IS NOT TRUE
$between: [6, 10], // BETWEEN 6 AND 10
$notBetween: [11, 15], // NOT BETWEEN 11 AND 15
$in: [1, 2], // IN [1, 2]
......@@ -259,13 +260,13 @@ something.findOne({
// Will order by otherfunction(`col1`, 12, 'lalala') DESC
[sequelize.fn('otherfunction', sequelize.col('col1'), 12, 'lalala'), 'DESC'],
// Will order by name on an associated User
[User, 'name', 'DESC'],
// Will order by name on an associated User aliased as Friend
[{model: User, as: 'Friend'}, 'name', 'DESC'],
// Will order by name on a nested associated Company of an associated User
[User, Company, 'name', 'DESC'],
]
......
......@@ -1851,6 +1851,42 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
});
});
});
it('does not compare the existence of associations', function () {
var self = this;
this.UserAssociationEqual = this.sequelize.define('UserAssociationEquals', {
username: DataTypes.STRING,
age: DataTypes.INTEGER
}, { timestamps: false });
this.ProjectAssociationEqual = this.sequelize.define('ProjectAssocationEquals', {
title: DataTypes.STRING,
overdue_days: DataTypes.INTEGER
}, { timestamps: false });
this.UserAssociationEqual.hasMany(this.ProjectAssociationEqual, { as: 'Projects', foreignKey: 'userId' });
this.ProjectAssociationEqual.belongsTo(this.UserAssociationEqual, { as: 'Users', foreignKey: 'userId' });
return this.UserAssociationEqual.sync({force: true}).then(function() {
return self.ProjectAssociationEqual.sync({force: true}).then(function () {
return self.UserAssociationEqual.create({ username: 'jimhalpert' }).then(function (user1) {
return self.ProjectAssociationEqual.create({ title: 'A Cool Project'}).then(function (project1) {
return user1.setProjects([project1]).then(function () {
return self.UserAssociationEqual.findOne({ where: { username: 'jimhalpert' }, include: [{model: self.ProjectAssociationEqual, as: 'Projects'}] }).then(function (user2) {
return self.UserAssociationEqual.create({ username: 'pambeesly' }).then(function (user3) {
expect(user1.get('Projects')).to.not.exist;
expect(user2.get('Projects')).to.exist;
expect(user1.equals(user2)).to.be.true;
expect(user1.equals(user3)).to.not.be.true;
});
});
});
});
});
});
});
});
});
describe('values', function() {
......
......@@ -369,6 +369,16 @@ if (Support.dialectIsMySQL()) {
arguments: ['myTable', {where: {field: {ne: null}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT NULL;',
context: QueryGenerator
}, {
title: 'use IS NOT if not === BOOLEAN',
arguments: ['myTable', {where: {field: {not: true}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT true;',
context: QueryGenerator
}, {
title: 'use != if not !== BOOLEAN',
arguments: ['myTable', {where: {field: {not: 3}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 3;',
context: QueryGenerator
}
],
......
......@@ -514,6 +514,16 @@ if (dialect.match(/^postgres/)) {
arguments: ['myTable', {where: {field: {ne: null}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT NULL;',
context: {options: {quoteIdentifiers: false}}
}, {
title: 'use IS NOT if not === BOOLEAN',
arguments: ['myTable', {where: {field: {not: true}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT true;',
context: {options: {quoteIdentifiers: false}}
}, {
title: 'use != if not !== BOOLEAN',
arguments: ['myTable', {where: {field: {not: 3}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field != 3;',
context: {options: {quoteIdentifiers: false}}
}
],
......
......@@ -347,6 +347,16 @@ if (dialect === 'sqlite') {
arguments: ['myTable', {where: {field: {ne: null}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT NULL;',
context: QueryGenerator
}, {
title: 'use IS NOT if not === BOOLEAN',
arguments: ['myTable', {where: {field: {not: true}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT 1;',
context: QueryGenerator
}, {
title: 'use != if not !== BOOLEAN',
arguments: ['myTable', {where: {field: {not: 3}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 3;',
context: QueryGenerator
}
],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!