Skip to content

hasMany setter uses bulk create and destroy to create and remove associations#690

Merged
durango merged 9 commits intosequelize:masterfrom
janmeier:hasmanyOptimization
Jun 11, 2013
Merged

hasMany setter uses bulk create and destroy to create and remove associations#690
durango merged 9 commits intosequelize:masterfrom
janmeier:hasmanyOptimization

Conversation

@janmeier
Copy link
Copy Markdown
Member

@janmeier janmeier commented Jun 9, 2013

In response to #104

Since we now have bulk create and updates available, there is no reason to do individual queries for each object. Instead of

Executing: INSERT INTO `x` (`a_id`,`b_id`) VALUES (1,1);
Executing: INSERT INTO `x` (`a_id`,`b_id`) VALUES (2,1);

We will now do

Executing: INSERT INTO `x` (`a_id`,`b_id`) VALUES (1,1), (2,1);

And similarly for deletions:

Executing: DELETE FROM `x` WHERE `a_id`=1 AND `b_id`=1 LIMIT 1;
Executing: DELETE FROM `x` WHERE `a_id`=1 AND `b_id`=2 LIMIT 1;

Becomes

Executing: DELETE FROM `x` WHERE `a_id`=1 AND `b_id` IN (1,2);

@durango
Copy link
Copy Markdown
Member

durango commented Jun 10, 2013

Can you do me a favor and add some simple tests to this such as checking for the "IN" part on the deletion as well as multiple values for inserts? This is not because of your code, but just in case someone makes a change down the road that breaks this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix this typo? :P

durango added a commit that referenced this pull request Jun 11, 2013
hasMany setter uses bulk create and destroy to create and remove associations
@durango durango merged commit df95670 into sequelize:master Jun 11, 2013
@janmeier janmeier deleted the hasmanyOptimization branch June 11, 2013 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants