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

Commit 043077ba by Mick Hansen

fix more tests

1 parent 00545f49
......@@ -9,6 +9,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [BUG] Fixed a bug with foreign keys pointing to attributes that were not integers. Now your primaryKey can be a string, and associations will still work. Thanks to @fixe [#1544](https://github.com/sequelize/sequelize/pull/1544)
- [BUG] Fix a case where createdAt timestamp would not be set when updatedAt was disabled Thanks to @fixe [#1543](https://github.com/sequelize/sequelize/pull/1543)
- [BUG] Fix a case where timestamps were not being write protected in `set` when underscored=true. janmeier [#1523](https://github.com/sequelize/sequelize/pull/1523)
- [FEATURE/BUG] Prefetching/includes now fully support schemas
#### Backwards compatability changes
......@@ -21,6 +22,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- if you have non-id primary keys you should go through your associations and set the foreignKey option if relying on a incorrect _id foreign key
- syncOnAssocation has been removed. It only worked for n:m, and having a synchronous function (hasMany) that invokes an asynchronous function (sync) without returning an emitter does not make a lot of sense. If you (implicitly) depended on this feature, sequelize.sync is your friend. If you do not want to do a full sync, use custom through models for n:m (`M1.hasMany(M2, { through: M3})`) and sync the through model explicitly.
- Join tables will be no longer be paranoid (have a deletedAt timestamp added), even though other models are.
- All tables in select queries will now be aliased with the model names to be support schemas. This will affect people stuff like `where: {'table.attribute': value}
# v1.7.0
- [FEATURE] covers more advanced include cases with limiting and filtering (specifically cases where a include would be in the subquery but its child include wouldnt be, for cases where a 1:1 association had a 1:M association as a nested include)
......
......@@ -68,7 +68,7 @@ module.exports = (function() {
var where = {}
params = params || {}
params.where = [params.where] || []
params.where = (params.where && [params.where]) || []
where[association.targetIdentifier] = this.get(association.identifier)
params.where.push(where)
......
......@@ -69,7 +69,7 @@ module.exports = (function() {
}
}
self.association.target.findAllJoin(through.getTableName(), options, queryOptions)
self.association.target.findAllJoin([through.getTableName(), through.name], options, queryOptions)
.on('success', function(objects) { customEventEmitter.emit('success', objects) })
.on('error', function(err){ customEventEmitter.emit('error', err) })
.on('sql', function(sql) { customEventEmitter.emit('sql', sql)})
......
......@@ -475,7 +475,7 @@ module.exports = (function() {
// whereCollection is used for non-primary key updates
this.options.whereCollection = optcpy.where || null;
return this.QueryInterface.select(this, [this.getTableName(), joinTableName], optcpy, Utils._.defaults({
return this.QueryInterface.select(this, [[this.getTableName(), this.name], joinTableName], optcpy, Utils._.defaults({
type: QueryTypes.SELECT
}, queryOptions, { transaction: (options || {}).transaction }))
}
......@@ -603,7 +603,7 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function (emitter) {
var col = this.sequelize.col('*')
if (options.include) {
col = this.sequelize.col(this.getTableName()+'.'+(this.primaryKeyAttributes[0] || 'id'))
col = this.sequelize.col(this.name+'.'+(this.primaryKeyAttribute))
}
options.attributes = [
......
......@@ -448,7 +448,7 @@ module.exports = (function() {
*/
DAO.prototype.reload = function(options) {
var where = [
this.QueryInterface.quoteIdentifier(this.Model.tableName) + '.' + this.QueryInterface.quoteIdentifier(this.Model.primaryKeyAttribute)+'=?',
this.QueryInterface.quoteTable(this.Model.name) + '.' + this.QueryInterface.quoteIdentifier(this.Model.primaryKeyAttribute)+'=?',
this.get(this.Model.primaryKeyAttribute, {raw: true})
]
......
......@@ -353,13 +353,13 @@ module.exports = (function() {
quoteTable: function(param, as) {
if (_.isObject(param)) {
var table = '';
if (as === true) {
as = param.as || param.name
as = param.as || param.name || param
}
if (_.isObject(param)) {
if (this._dialect.supports.schemas) {
if (param.schema) {
table += this.quoteIdentifier(param.schema) + '.'
......@@ -375,13 +375,15 @@ module.exports = (function() {
table = this.quoteIdentifier(table)
}
} else {
table = this.quoteIdentifier(param)
}
if (as) {
table += " AS " + this.quoteIdentifier(as)
}
return table
}
return this.quoteIdentifier(param)
},
/*
......@@ -593,10 +595,13 @@ module.exports = (function() {
, subJoinQueries = []
, mainTableAs = null
if (!Array.isArray(tableName)) {
if (!Array.isArray(tableName) && Model) {
options.tableAs = mainTableAs = this.quoteTable(Model.name)
}
options.table = table = !Array.isArray(tableName) ? this.quoteTable(tableName) : tableName.map(function(t) {
if (Array.isArray(t)) {
return this.quoteTable(t[0], t[1])
}
return this.quoteTable(t, true)
}.bind(this)).join(", ")
......
......@@ -127,7 +127,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this.Article.hasMany(this.Label)
this.sequelize.sync({ force: true }).success(function() {
this.sequelize.sync({ force: true }).done(function(err) {
expect(err).not.to.be.ok
done()
})
})
......@@ -139,7 +140,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
Article.hasMany(Label)
sequelize.sync({ force: true }).success(function() {
sequelize.sync({ force: true }).done(function(err) {
expect(err).not.to.be.ok
Article.create({ title: 'foo' }).success(function(article) {
Label.create({ text: 'bar' }).success(function(label) {
sequelize.transaction(function(t) {
......@@ -615,7 +617,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
it("get associated objects with an eager load", function(done) {
this.User.find({where: {username: 'John'}, include: [ this.Task ]}).success(function (john) {
this.User.find({where: {username: 'John'}, include: [ this.Task ]}).done(function (err, john) {
expect(err).not.to.be.ok
expect(john.tasks).to.have.length(2);
done();
})
......
......@@ -17,12 +17,13 @@ describe(Support.getTestDialectTeaser("Self"), function() {
freezeTableName: true
});
Group.belongsTo(Group, { foreignKey: 'parent' });
Group.belongsTo(Group, { as: 'Parent', foreignKey: 'parent_id' });
Group.sync({force: true}).done(function (err) {
expect(err).not.to.be.ok
Group.findAll({
include: [{
model: Group
model: Group,
as: 'Parent'
}]
}).done(function (err) {
expect(err).not.to.be.ok
......
......@@ -59,10 +59,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
where: Sequelize[method]( { username: "foo", intVal: 2 }, { secretValue: 'bar' } )
}).on('sql', function(sql) {
var expectation = ({
mysql: "WHERE (`Users`.`username`='foo' AND `Users`.`intVal`=2 " + word + " `Users`.`secretValue`='bar')",
sqlite: "WHERE (`Users`.`username`='foo' AND `Users`.`intVal`=2 " + word + " `Users`.`secretValue`='bar')",
postgres: 'WHERE ("Users"."username"=\'foo\' AND "Users"."intVal"=2 ' + word + ' "Users"."secretValue"=\'bar\')',
mariadb: "WHERE (`Users`.`username`='foo' AND `Users`.`intVal`=2 " + word + " `Users`.`secretValue`='bar')"
mysql: "WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 " + word + " `User`.`secretValue`='bar')",
sqlite: "WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 " + word + " `User`.`secretValue`='bar')",
postgres: 'WHERE ("User"."username"=\'foo\' AND "User"."intVal"=2 ' + word + ' "User"."secretValue"=\'bar\')',
mariadb: "WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 " + word + " `User`.`secretValue`='bar')"
})[Support.getTestDialect()]
if (!expectation) {
......@@ -81,10 +81,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
where: Sequelize[method]( 1, 2 )
}).on('sql', function(sql) {
var expectation = ({
mysql: "WHERE (`Users`.`id`=1 " + word + " `Users`.`id`=2)",
sqlite: "WHERE (`Users`.`id`=1 " + word + " `Users`.`id`=2)",
postgres: 'WHERE ("Users"."id"=1 ' + word + ' "Users"."id"=2)',
mariadb: "WHERE (`Users`.`id`=1 " + word + " `Users`.`id`=2)"
mysql: "WHERE (`User`.`id`=1 " + word + " `User`.`id`=2)",
sqlite: "WHERE (`User`.`id`=1 " + word + " `User`.`id`=2)",
postgres: 'WHERE ("User"."id"=1 ' + word + ' "User"."id"=2)',
mariadb: "WHERE (`User`.`id`=1 " + word + " `User`.`id`=2)"
})[Support.getTestDialect()]
if (!expectation) {
......@@ -150,16 +150,16 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
if (Support.getTestDialect() === 'postgres') {
expect(sql).to.contain(
'WHERE (' + [
'"Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\' AND ',
'"User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\' AND ',
'(',
'"Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\' OR ',
'("Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\') OR ',
'("Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\')',
'"User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\' OR ',
'("User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\') OR ',
'("User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\')',
') AND ',
'(',
'"Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\' AND ',
'("Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\') AND ',
'("Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\')',
'"User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\' AND ',
'("User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\') AND ',
'("User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\')',
')'
].join("") +
')'
......@@ -167,16 +167,16 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
} else {
expect(sql).to.contain(
"WHERE (" + [
"`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo' AND ",
"`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo' AND ",
"(",
"`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo' OR ",
"(`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo') OR ",
"(`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo')",
"`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo' OR ",
"(`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo') OR ",
"(`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo')",
") AND ",
"(",
"`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo' AND ",
"(`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo') AND ",
"(`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo')",
"`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo' AND ",
"(`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo') AND ",
"(`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo')",
")"
].join("") +
")"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!