Skip to content
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

Are mysql users out of luck when it comes to saving associations in bulk? #422

Closed
jgoodall628 opened this issue May 15, 2017 · 5 comments
Closed

Comments

@jgoodall628
Copy link

No description provided.

@seanlinsley
Copy link
Contributor

I'm not sure what you mean; this gem already has upsert support for MySQL (though I haven't used it myself).

@jkowens
Copy link
Collaborator

jkowens commented May 16, 2017

The options for MySQL are not great. After importing, you could possibly query based on a column like updated_at where the value is greater than a timestamp before insert. You could use the returned objects to build out the associations. I believe both queries would need to be within a transaction.

@jkowens
Copy link
Collaborator

jkowens commented May 22, 2017

I'm going to close this issue. My only other suggestion would be to try StackOverflow for ideas retrieving previously inserted IDs.

@jkowens jkowens closed this as completed May 22, 2017
@jasonperrone
Copy link

Guessing the situation here hasn't changed? If a MySQL user wants to bulk import models along with their has_many association(s), they can't use this Gem, correct? Well I mean I can still use it, but I have to be willing to set the associations later after bulk importing the models, totally eliminating the benefit of the bulk import, right?

@jkowens
Copy link
Collaborator

jkowens commented Jun 9, 2018

As far as I know MySQL still doesn't offer a way to return all the IDs of the inserted rows. It's hard to say if that eliminates the benefit of bulk import for you or not. If you can possibly reduce the number of inserts executed, you will likely see some improved performance.

If you are using auto increment primary keys and the MySQL setting innodb_autoinc_lock_mode is set to 0 or 1, you can possibly get the last_inserted_id and calculate ids generated for the number of records inserted. More info here: #279

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

No branches or pull requests

4 participants