-
Notifications
You must be signed in to change notification settings - Fork 791
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
to_param incorrectly returns nil for an unpersisted object #804
Comments
This makes it possible to use with Elasticsearch due to: elastic/elasticsearch-rails#804
This makes it possible to use with Elasticsearch due to: elastic/elasticsearch-rails#804
Hi @jcoyne I'm sorry you're running into this inconsistency between Typically, we would work to fix bugs in the elasticsearch gems but we have plans to deprecate the ActiveRecord pattern ( I recommend checking out the Repository pattern in the If you don't mind, I'd like to close this issue as it's unlikely we will work on it. Thanks for your understanding. |
Hi @jcoyne, I'm going to close this issue. Please open a new one if you have further questions. Thanks |
I am using the repository pattern. But I’d still like the to_param to behave consistently in order to use the rails route helpers. |
Hi @jcoyne, in your example above, you've included the |
Sure. I'm retrieving an object like this: repo = Elasticsearch::Persistence::Repository.new do
klass Document
end
@doc = repo.find(id) Now, when I want to route to a controller to handle that document using the rails routing helpers I am doing: <%= link_to 'More info', @doc %> In order to do that latter part, you need to include |
@jcoyne You can also define the |
@jcoyne I just wanted to check in and see if you could define |
Yeah, I can add all that ActiveModel stuff myself. Thanks for following up. |
On an ActiveRecord model (see
User
below), callingto_param
on an unsaved object returns it's key. This is part ofActiveRecord::Integration
however onElasticsearch::Persistence::Model
callingto_param
on an unsaved object returns nil. It would be nice ifElasticsearch::Persistence::Model
matched the behavior ofActiveRecord::Integration
: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/integration.rb#L49-L52The text was updated successfully, but these errors were encountered: