Is there any way to do
@destination.ratings.where(:name => 'monkey')
when none of the models are yet persisted?
No there isn't, but you may just use normal Ruby methods like Array#select
to go through your unsaved models.
The where
method and its bandmates in ActiveRecord generate SQL queries for the database, so if the model instances aren't in the database, it won't find anything.
Something like
@monkey = @destination.ratings.select{|rating| rating.name == 'monkey' }.first
could do the trick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With