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

Commit 19828b24 by Sascha Depold

Merge branch 'master' of https://github.com/chill117/sequelize into chill117-master

2 parents 5f882ec7 6445ee27
Showing with 59 additions and 1 deletions
...@@ -1075,7 +1075,10 @@ module.exports = (function() { ...@@ -1075,7 +1075,10 @@ module.exports = (function() {
if (include.hasOwnProperty('attributes')) { if (include.hasOwnProperty('attributes')) {
var primaryKeys; var primaryKeys;
if (include.daoFactory.hasPrimaryKeys) { if (include.daoFactory.hasPrimaryKeys) {
primaryKeys = include.daoFactory.primaryKeys primaryKeys = []
for (var field_name in include.daoFactory.primaryKeys) {
primaryKeys.push(field_name)
}
} else { } else {
primaryKeys = ['id'] primaryKeys = ['id']
} }
......
...@@ -2056,6 +2056,61 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -2056,6 +2056,61 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('getting parent data in many to one relationship', function(done) {
var self = this;
var User = self.sequelize.define('User', {
id: {type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true},
username: {type: Sequelize.STRING}
})
var Message = self.sequelize.define('Message', {
id: {type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true},
user_id: {type: Sequelize.INTEGER},
message: {type: Sequelize.STRING}
})
User.hasMany(Message)
Message.belongsTo(User, { foreignKey: 'user_id' })
Message.sync({ force: true }).success(function() {
User.sync({ force: true }).success(function() {
User.create({username: 'test_testerson'}).success(function(user) {
Message.create({user_id: user.id, message: 'hi there!'}).success(function(message) {
Message.create({user_id: user.id, message: 'a second message'}).success(function(message) {
Message.findAll({
where: {user_id: user.id},
attributes: [
'user_id',
'message'
],
include: [{ model: User, as: User.tableName, attributes: ['username'] }]
}).success(function(messages) {
expect(messages.length).to.equal(2);
expect(messages[0].message).to.equal('hi there!');
expect(messages[0].user.username).to.equal('test_testerson');
expect(messages[1].message).to.equal('a second message');
expect(messages[1].user.username).to.equal('test_testerson');
done()
})
})
})
})
})
})
})
it('allows mulitple assocations of the same model with different alias', function (done) { it('allows mulitple assocations of the same model with different alias', function (done) {
var self = this var self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!