> player.records
Record Load (0.5ms) SELECT * FROM `records` WHERE (`records`.player_id = 1)
> player.records.first(:conditions => {:metric_id => "IS NOT NULL"})
Record Load (0.5ms) SELECT * FROM `records` WHERE (`records`.player_id = 1 AND (`records`.`metric_id` = 'IS NOT NULL')) LIMIT 1
Is there a way to make the second query not hit the database, but use the cache instead? It seems a bit excessive for it to be hitting the database again when they data is already in memory.
I need both results. I’m aware that Ruby can iterate through the values, but I’d prefer to do this through ActiveRecord if possible. I’m coming from a Django background where filter() did this just fine.
I’m using Rails 2.3.
No, simply because the condition is different.
But try to explain the context. Why do you need to use both queries? Can’t you use only the second one?
If you need both, why can’t you filter the Array with Ruby code instead of making another query?