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

Commit df42db65 by Mick Hansen

Fix 1:M selfAssociations with aliases

1 parent a31b5d28
......@@ -19,7 +19,7 @@ module.exports = (function() {
this.sequelize = source.daoFactoryManager.sequelize
this.through = options.through
this.isMultiAssociation = true
this.isSelfAssociation = (this.source.tableName === this.target.tableName)
this.isSelfAssociation = this.source === this.target
this.doubleLinked = false
this.combinedTableName = Utils.combineTableNames(
this.source.tableName,
......@@ -136,7 +136,7 @@ module.exports = (function() {
// is there already a single sided association between the source and the target?
// or is the association on the model itself?
if ((this.isSelfAssociation && this.through) || doubleLinked) {
if ((this.isSelfAssociation && Object(this.through) === this.through) || doubleLinked) {
// remove the obsolete association identifier from the source
if (this.isSelfAssociation) {
this.foreignIdentifier = Utils._.underscoredIf((this.options.as || this.target.tableName) + 'Id', this.options.underscored)
......
......@@ -518,7 +518,17 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}) // end optimization using bulk create, destroy and update
describe('selfAssociations', function () {
it('should work', function (done) {
it('should work with alias', function (done) {
var Person = this.sequelize.define('Group', {})
Person.hasMany(Person, { as: 'Children'});
this.sequelize.sync().done(function (err) {
expect(err).not.to.be.ok
done()
})
})
it('should work with through', function (done) {
var Group = this.sequelize.define('Group', {})
Group.hasMany(Group, { through: 'groups_outsourcing_companies', as: 'OutsourcingCompanies'});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!