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

Commit 751a6de3 by Sascha Depold

Merge pull request #132 from skystrife/master

Fix bug with multiple belongsTo associations referring to the same table.
2 parents b494f985 7b8ebab3
# v1.3.7 #
- [BUG] fixed issue where multiple belongsTo or hasOne associations to the same table overwrite each other
# v1.3.6 #
- [BUG] don't update an existing updatedAt-attribute if timestamps option for a DAO is false
......
......@@ -13,7 +13,7 @@ module.exports = (function() {
this.associationAccessor = this.isSelfAssociation
? Utils.combineTableNames(this.target.tableName, this.options.as || this.target.tableName)
: this.target.tableName
: this.options.as || this.target.tableName
}
// the id is in the source table
......
......@@ -13,7 +13,7 @@ module.exports = (function() {
this.associationAccessor = this.isSelfAssociation
? Utils.combineTableNames(this.target.tableName, this.options.as || this.target.tableName)
: this.target.tableName
: this.options.as || this.target.tableName
this.accessors = {
get: Utils._.camelize('get_' + (this.options.as || Utils.singularize(this.target.tableName))),
......
{
"name": "sequelize",
"description": "MySQL ORM for Node.JS",
"version": "1.3.6",
"version": "1.3.7",
"author": "Sascha Depold <sascha@depold.com>",
"contributors": [
{ "name": "Sascha Depold", "email": "sascha@depold.com" },
{ "name": "Meg Sharkey", "email": "meg@metamarkets.com" }
{ "name": "Meg Sharkey", "email": "meg@metamarkets.com" },
{ "name": "Chase Geigle", "email": "sky@skytrife.com" }
],
"dependencies": {
"mysql": "0.9.x",
......
......@@ -47,6 +47,17 @@ describe('BelongsTo', function() {
expect(task.getPerson).toBeDefined()
})
it("aliases associations to the same table according to the passed 'as' option", function() {
Task.belongsTo(User, {as: 'Poster'})
Task.belongsTo(User, {as: 'Owner'})
var task = Task.build({title: 'asd'})
expect(task.getPoster).toBeDefined()
expect(task.setPoster).toBeDefined()
expect(task.getOwner).toBeDefined()
expect(task.setOwner).toBeDefined()
})
it("intializes the foreign key with null", function() {
Task.belongsTo(User)
......
......@@ -54,6 +54,17 @@ describe('HasOne', function() {
expect(u.getWork).toBeDefined()
})
it("aliases associations to the same table according to the passed 'as' option", function() {
User.hasOne(Task, {as: 'Work'});
User.hasOne(Task, {as: 'Play'});
var u = User.build({username: 'asd'})
expect(u.getWork).toBeDefined()
expect(u.setWork).toBeDefined()
expect(u.getPlay).toBeDefined()
expect(u.setPlay).toBeDefined()
})
it("gets and sets the correct objects", function() {
var user, task;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!