-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support on_duplicate_key_update for recursive imports #778
Conversation
hey @ramblex , thanks for adding this functionality to gem, but can you plz tell me if your code has capability to handle n number of associations with nested child also? like book has many topics and topic has many sub_topics |
@ramblex i think if you make it recursive then it may fix this problem |
I am in need of this feature. |
Hi @saqlainriaz, recursive_on_duplicate_key_update supports specifying which columns to update for nested associations using something like the following where the tree is topics -> books -> chapters.
I've added in a test to show it working. One possible issue, however, is that the leaf objects (chapters in the example) are only imported if the intermediate objects (books in the example) have been changed, but that seems to be a more general issue - |
This would also greatly benefit us |
this would help us too |
Released in v1.7.0! |
Hello, this PR adds support for specifying separate
on_duplicate_key_update
options for associations when doing a recursive import. I couldn't find a way of doing that with the existing code - the closest seemed to be passing in :all but that didn't quite do what I needed. Apologies if I've missed if this is already possible..The PR adds a new
recursive_on_duplicate_key_update
option toimport
whereon_duplicate_key_update
options can be specified for each of the associations. The new option takes a Hash as its value where the keys are the table names and the values are the options normally passed to on_duplicate_key_update.In the example below
[:id]
is used as the on_duplicate_key_update option when importing topics and{ conflict_target: [:id], columns: [:author_name] }
is used as the on_duplicate_key_update option when importing books.Many thanks for this fantastic gem..!