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

ActiveRecord#find needs an id, even when to_param and from_param has an override #7092

Closed
deepak opened this issue Jul 18, 2012 · 2 comments
Closed

Comments

@deepak
Copy link
Contributor

deepak commented Jul 18, 2012

Have a ActiveRecord model, which overrides to_param and from_param
but ActiveRecord#find does not use from_param.
to_param needs the id to be appended to it, for AR#find to work

explained at http://apidock.com/rails/ActiveRecord/Base/to_param, by balint_erdi in the comments
example at: https://gist.github.com/3135755

@acapilleri
Copy link
Contributor

find(123-hello)is equal find(123)because 123-hello  is typecastedto the type of colum in this case the ìd that is an integer, infact "123-hello".to_i == 1234
Anyway this is not a issue, if you have any new proposals you can send an email or post a message to rails core team google group

@carlosantoniodasilva
Copy link
Member

Yeah, @acapilleri got it right. When using some sort of slug that starts with id, that works out of the box because of typecasting, and find will always receive an id - or array of ids.

from_param does not exist in Active Record, the tip existent in apidock is solely to keep methods in sync in your app, so you have a single finder to use wherever needed, but AR has no knowledge of it.

Thanks!

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