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

Commit 0258fff3 by Mick Hansen

Merge branch 'GuilhermeReda-master'

2 parents 68709eea 926af888
...@@ -1094,7 +1094,7 @@ module.exports = (function() { ...@@ -1094,7 +1094,7 @@ module.exports = (function() {
if (association.associationType !== 'BelongsTo') { if (association.associationType !== 'BelongsTo') {
// Alias the left attribute if the left attribute is not from a subqueried main table // Alias the left attribute if the left attribute is not from a subqueried main table
// When doing a query like SELECT aliasedKey FROM (SELECT primaryKey FROM primaryTable) only aliasedKey is available to the join, this is not the case when doing a regular select where you can't used the aliased attribute // When doing a query like SELECT aliasedKey FROM (SELECT primaryKey FROM primaryTable) only aliasedKey is available to the join, this is not the case when doing a regular select where you can't used the aliased attribute
if (!subQuery || (subQuery && !include.subQuery && include.parent.model !== mainModel)) { if (!subQuery || (subQuery && include.parent.model !== mainModel)) {
if (left.rawAttributes[attrLeft].field) { if (left.rawAttributes[attrLeft].field) {
attrLeft = left.rawAttributes[attrLeft].field; attrLeft = left.rawAttributes[attrLeft].field;
} }
......
...@@ -1999,6 +1999,79 @@ describe(Support.getTestDialectTeaser('Include'), function() { ...@@ -1999,6 +1999,79 @@ describe(Support.getTestDialectTeaser('Include'), function() {
}); });
}); });
}); });
it('should work on a nested set of required 1:1 relations', function () {
var Person = this.sequelize.define("Person", {
name: {
type : Sequelize.STRING,
allowNull : false
}
});
var UserPerson = this.sequelize.define("UserPerson", {
PersonId: {
type : Sequelize.INTEGER,
primaryKey : true,
references : Person,
referencesKey : 'id',
field : 'id'
},
rank: {
type : Sequelize.STRING
}
});
var User = this.sequelize.define("User", {
UserPersonId: {
type : Sequelize.INTEGER,
primaryKey : true,
references : UserPerson,
referencesKey : 'id',
field : 'id'
},
login: {
type : Sequelize.STRING,
unique : true,
allowNull : false,
}
});
Person.hasOne(UserPerson);
UserPerson.belongsTo(Person, {
foreignKey: {
allowNull: false
}
});
UserPerson.hasOne(User);
User.belongsTo(UserPerson, {
foreignKey: {
name: 'UserPersonId',
allowNull: false
}
});
return this.sequelize.sync({force: true}).then(function () {
return Person.findAll({
offset : 0,
limit : 20,
attributes : ['id', 'name'],
include : [{
model : UserPerson,
required : true,
attributes : ['rank'],
include : [{
model : User,
required : true,
attributes : ['login']
}]
}]
});
});
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!