-
Notifications
You must be signed in to change notification settings - Fork 617
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
Importing an array of hashes ignores columns not in the first hash #507
Comments
points for use of |
Are you using a version older than 0.21.0? I believe this issue was addressed in that release. |
Thanks for the response, looks like I'm off by a version. Can this be documented somewhere? Since this use case isn't supported (it raises an exception), I feel like it's a worthy addition to the docs. Maybe here? I realize that isn't what the example is doing, but it doesn't explicitly say that it isn't possible either. Also, looking through the discussion of how the decision of raising an exception came to be, I'm not sure I understand the concerns with setting the values to column defaults. That is, after all, the default behavior for ActiveRecord (or any insert query where you don't specify the value of a column for that matter) and I think a valid expectation for this gem is that it would do the same. It would nice to have that as an option at least. I'm happy to create PRs for any of my suggestions if we are in agreement. |
Absolutely, this should definitely be documented at that wiki page. For now, an example of how to group group hashes by keys as suggested would be nice as well:
See: #465 (comment) I'll have to give more thought to your suggestion of using the column default. One concern I possibly have is that when using |
To make sure I'm understanding correctly - this is a bug that is solved in the latest version and you still want it documented in the README? |
This bug was addressed in 0.21.0 by raising an exception instead of silently doing the counter-intuitive behavior I described. My proposal was to document the fact that this use case isn't supported, that it will raise an exception, and that the work-around I talked about should be used instead. |
@jkowens is there any possibility of just allowing a default value? (nil) Part of the entire reason of using this gem is so I DONT have to instantiate tons of unecessary objects, I'm bulk inserting 100's of millions of records. It would be cool to just have it default to nil if its missing so the expected value is null like in OPs issue |
Title says it all. Say we have table
Foo
with columnsid
,bar
,baz
, and want to import the following:This creates the rows:
instead of the expected:
It's possible to get around this by using
ActiveRecord
objects, for example:but this is still a rather pernicious bug.
The text was updated successfully, but these errors were encountered: