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

Proposal: .import should accept array-like objects #785

Open
mattvague opened this issue Nov 10, 2022 · 0 comments
Open

Proposal: .import should accept array-like objects #785

mattvague opened this issue Nov 10, 2022 · 0 comments

Comments

@mattvague
Copy link

Hi there, I was recently trying to do something like

things = Thing.where(attr: 'baz').each { |t| t.other_attr = 'bar' }
Thing.import(things)

and was confused about why I was getting a ArgumentError: Invalid arguments! error. As pointed out in this issue, simply calling Thing.import(things.to_a) would fix things since things would be an ActiveRecord_Relation however, I'd like to propose that .import should be more liberal in what it accepts and that this should be a valid use case.

Instead of doing strict args.last.is_a?( Array ) checks like this should instead maybe check if args.last responds to to_a and if so then calls that first.

Also, maybe we could improve these error message a bit to be more specific about why the arguments are invalid?

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

1 participant