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

Why the ID column is being removed from default columns #39

Closed
randavidovitz opened this issue Aug 15, 2018 · 2 comments
Closed

Why the ID column is being removed from default columns #39

randavidovitz opened this issue Aug 15, 2018 · 2 comments

Comments

@randavidovitz
Copy link

I saw a case that when i try to add a rows with a given ID not using the ID and the code review shows we are removing it

Why ?

@jamis
Copy link
Owner

jamis commented Aug 18, 2018

Hello, thanks for trying BulkInsert! I think you're seeing that the id column is being removed from the default set of column names; this is because, by default, Rails prefers to manage the id column itself. If you want to include an explicit id, it ought to work to specify the list of column names directly, instead of relying on the default set of column names. Something like this:

MyModel.bulk_insert(MyModel.column_names, values: [array, of, rows, to, insert])

Let me know if that doesn't work for you.

@jamis jamis closed this as completed Aug 18, 2018
@gordysc
Copy link

gordysc commented Mar 23, 2019

Just in case someone else stumbles upon this, you want to pass in the column names like so:

MyModel.bulk_insert(*MyModel.column_names, values: [array, of, rows, to, insert])

Notice the *...

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

3 participants