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

Argument error could be more informative #23

Open
andrewcroome opened this issue Apr 5, 2018 · 1 comment
Open

Argument error could be more informative #23

andrewcroome opened this issue Apr 5, 2018 · 1 comment

Comments

@andrewcroome
Copy link

I recently managed to create a join table for image attachments on news items in which I failed to define a primary key like the below:

primary_key [:news_item_id, :asset_id]

The first sign of my mistake was rom-factory raising the following error when calling the relation's factory:

ArgumentError:
       ROM::Relation::Combined#by_pk arity is 1 (0 args given)

I was able to find my mistake with help from @timriley, but I wonder if we could add mention to that error to check one's primary key as a pointer to others?

The top of the stacktrace was:

/Users/andrewcroome/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-core-4.2.0/lib/rom/relation/curried.rb:73:in `to_a'
/Users/andrewcroome/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-core-4.2.0/lib/rom/relation/materializable.rb:55:in `first'
/Users/andrewcroome/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-factory-0.6.0/lib/rom/factory/builder/persistable.rb:31:in `create'
@timriley
Copy link
Member

timriley commented Apr 5, 2018

Thinking we could raise our own error if pk in

pk = primary_key_names.map { |key| persisted[key] }
is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants