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

Commit 68acb801 by Mick Hansen

feat(model/attributes): primary key support for source tables for includes, closes #1809

1 parent c4606736
......@@ -785,13 +785,18 @@ module.exports = (function() {
}
}
} else {
var primaryKeysLeft = association.associationType === 'BelongsTo' ? association.target.primaryKeyAttributes : include.association.source.primaryKeyAttributes
var left = association.associationType === 'BelongsTo' ? association.target : include.association.source
, primaryKeysLeft = association.associationType === 'BelongsTo' ? left.primaryKeyAttributes : left.primaryKeyAttributes
, tableLeft = association.associationType === 'BelongsTo' ? as : parentTable
, attrLeft = primaryKeysLeft[0]
, tableRight = association.associationType === 'BelongsTo' ? parentTable : as
, attrRight = association.identifier
, joinOn;
if (left.rawAttributes[attrLeft].field) {
attrLeft = left.rawAttributes[attrLeft].field;
}
// Filter statement
// Used by both join and subquery where
joinOn =
......
......@@ -506,6 +506,16 @@ module.exports = (function() {
} else {
var identifier = self.primaryKeyValues;
if (identifier) {
for (var attrName in identifier) {
// Field name mapping
if (self.Model.rawAttributes[attrName].field) {
identifier[self.Model.rawAttributes[attrName].field] = identifier[attrName];
delete identifier[attrName];
}
}
}
if (identifier === null && self.__options.whereCollection !== null) {
identifier = self.__options.whereCollection;
}
......
......@@ -85,7 +85,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
type: DataTypes.STRING
}
})
])
]);
});
it('should create, fetch and update with alternative field names from a simple model', function () {
......@@ -108,7 +108,9 @@ describe(Support.getTestDialectTeaser("Model"), function () {
});
}).then(function (user) {
expect(user.get('name')).to.equal('Barfoo');
})
}).on('sql', function (sql) {
console.log(sql);
});
});
it('should work with attributes and where on includes', function () {
......@@ -131,6 +133,8 @@ describe(Support.getTestDialectTeaser("Model"), function () {
expect(user.get('name')).to.be.ok;
expect(user.get('tasks')[0].get('title')).to.equal('DoDat');
});
}).on('sql', function (sql) {
console.log(sql);
});
});
......@@ -147,7 +151,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
});
}).then(function (user) {
expect(user).to.be.ok
})
});
});
it('should work with bulkCreate and findAll', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!