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

Association helper does not use correct primary key if it is other than "id" #19

Closed
massive opened this issue Jul 1, 2010 · 2 comments

Comments

@massive
Copy link

massive commented Jul 1, 2010

It seems that association method does not use non-standard primary key even if it is defined in the model.

This works:
<%= f.association :game, :collection => Game.multiplayer.order('name'), :value_method => Game.primary_key %>

This doesn't:
<%= f.association :game, :collection => Game.multiplayer.order('name') %>

Is this intended behavior or a bug?

@carlosantoniodasilva
Copy link
Member

You need to pass an array to collection, with label and value methods... Please try:

Game.multiplayer.order('name').map{|game| [game.name, game.my_pk_attr] }

There is no support for passing an AR collection, but you could try a patch =).

@massive
Copy link
Author

massive commented Jul 2, 2010

Ok, thank you. ...thinking of doing a patch... :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants