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

Commit 559ccac6 by Jan Aagaard Meier

Return the target model instead of the join model when using createAssociation w…

…ith n:m. Closes #1765
1 parent 32de5849
...@@ -7,6 +7,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell ...@@ -7,6 +7,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [FEATURE] `define()` stores models in `sequelize.models` Object e.g. `sequelize.models.MyModel` - [FEATURE] `define()` stores models in `sequelize.models` Object e.g. `sequelize.models.MyModel`
- [FEATURE] The `set` / `add` / `has` methods for associations now allow you to pass the value of a primary key, instead of a full Instance object, like so: `user.addTask(15);`. - [FEATURE] The `set` / `add` / `has` methods for associations now allow you to pass the value of a primary key, instead of a full Instance object, like so: `user.addTask(15);`.
- [FEATURE] Support for FOR UPDATE and FOR SHARE statements [#1777](https://github.com/sequelize/sequelize/pull/1777) - [FEATURE] Support for FOR UPDATE and FOR SHARE statements [#1777](https://github.com/sequelize/sequelize/pull/1777)
- [FEATURE] n:m createAssocation now returns the target model instance instead of the join model instance
- [BUG] An error is now thrown if an association would create a naming conflict between the association and the foreign key when doing eager loading. Closes [#1272](https://github.com/sequelize/sequelize/issues/1272) - [BUG] An error is now thrown if an association would create a naming conflict between the association and the foreign key when doing eager loading. Closes [#1272](https://github.com/sequelize/sequelize/issues/1272)
- [INTERNALS] `bulkDeleteQuery` was removed from the MySQL / abstract query generator, since it was never used internally. Please use `deleteQuery` instead. - [INTERNALS] `bulkDeleteQuery` was removed from the MySQL / abstract query generator, since it was never used internally. Please use `deleteQuery` instead.
......
...@@ -442,7 +442,7 @@ module.exports = (function() { ...@@ -442,7 +442,7 @@ module.exports = (function() {
if (Object(association.through) === association.through) { if (Object(association.through) === association.through) {
// Create the related model instance // Create the related model instance
return association.target.create(values, fieldsOrOptions).then(function(newAssociatedObject) { return association.target.create(values, fieldsOrOptions).then(function(newAssociatedObject) {
return instance[association.accessors.add](newAssociatedObject, options) return instance[association.accessors.add](newAssociatedObject, options).return(newAssociatedObject)
}) })
} else { } else {
values[association.identifier] = instance.get(association.source.primaryKeyAttribute); values[association.identifier] = instance.get(association.source.primaryKeyAttribute);
......
...@@ -78,7 +78,7 @@ var Mixin = module.exports = function(){} ...@@ -78,7 +78,7 @@ var Mixin = module.exports = function(){}
* *
* The following methods are injected on the source: * The following methods are injected on the source:
* *
* * get[AS] - for example getProfile() * * get[AS] - for example getProfile(finder). The finder object is passed to `target.find`.
* * set[AS] - for example setProfile(instance, options). Options are passed to `target.save` * * set[AS] - for example setProfile(instance, options). Options are passed to `target.save`
* * create[AS] - for example createProfile(value, options). Builds and saves a new instance of the associated model. Values and options are passed on to `target.create` * * create[AS] - for example createProfile(value, options). Builds and saves a new instance of the associated model. Values and options are passed on to `target.create`
* *
...@@ -119,7 +119,7 @@ Mixin.hasOne = function(targetModel, options) { ...@@ -119,7 +119,7 @@ Mixin.hasOne = function(targetModel, options) {
* *
* The following methods are injected on the source: * The following methods are injected on the source:
* *
* * get[AS] - for example getUser() * * get[AS] - for example getUser(finder). The finder object is passed to `target.find`.
* * set[AS] - for example setUser(instance, options). Options are passed to this.save * * set[AS] - for example setUser(instance, options). Options are passed to this.save
* * create[AS] - for example createUser(value, options). Builds and saves a new instance of the associated model. Values and options are passed on to target.create * * create[AS] - for example createUser(value, options). Builds and saves a new instance of the associated model. Values and options are passed on to target.create
* *
...@@ -169,7 +169,7 @@ Mixin.belongsTo = function(targetModel, options) { ...@@ -169,7 +169,7 @@ Mixin.belongsTo = function(targetModel, options) {
* The following methods are injected on the source: * The following methods are injected on the source:
* *
* * get[AS] - for example getPictures(). * * get[AS] - for example getPictures(finder). The finder object is passed to `target.find`.
* * set[AS] - for example setPictures(instances, defaultAttributes|options). Update the associations. All currently associated models that are not in instances will be removed. * * set[AS] - for example setPictures(instances, defaultAttributes|options). Update the associations. All currently associated models that are not in instances will be removed.
* * add[AS] - for example addPicture(instance, defaultAttributes|options). Add another associated object. * * add[AS] - for example addPicture(instance, defaultAttributes|options). Add another associated object.
* * add[AS] [plural] - for example addPictures([instance1, instance2], defaultAttributes|options). Add some more associated objects. * * add[AS] [plural] - for example addPictures([instance1, instance2], defaultAttributes|options). Add some more associated objects.
......
...@@ -998,7 +998,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -998,7 +998,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this.sequelize.sync({ force: true }).success(function() { this.sequelize.sync({ force: true }).success(function() {
Task.create({ title: 'task' }).success(function(task) { Task.create({ title: 'task' }).success(function(task) {
task.createUser({ username: 'foo' }).success(function() { task.createUser({ username: 'foo' }).success(function(createdUser) {
expect(createdUser.Model).to.equal(User)
expect(createdUser.username).to.equal('foo')
task.getUsers().success(function(_users) { task.getUsers().success(function(_users) {
expect(_users).to.have.length(1) expect(_users).to.have.length(1)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!