Closed vanharen closed 13 years ago
find(:all) is not supported and will not be supported. The conditions parser should convert the find_all to find_from_ids, don't know why it's not at the moment.
The find_from_ids should work. I'll dig into why it isn't.
Sorry, just to clarify: find all with conditions is working fine. The parser is converting to find_from_ids just fine. That's all good.
The mystery is why doesn't User.find([100,101,102]) work, since it's functionally equivalent. (Though I know it's different code paths, of course.)
And then why User.find(100,101,102) works only if some of the users are already cached, but complains it is UNCACHEABLE if none of them are already cached. That one baffles me.
Lastly, might I also add a "thanks!" both for maintaining this fork, and for replying so quickly. It's a great project and it's nice to see it get attention.
I just looked through the finder test and it should be working fine. see finders_spec.rb #find([1, 2, ...], :conditions => ...)
See if you can get this test to fail as you are seeing in your code.
Okay, we are working on a test for this and will try to fix it ASAP.
I ran into this issue as well, after looking through the code the reason why Model.find([1,2,3]) does not add the objects to the cache if more than 2 of them are uncached is because fetch does not call add on missed keys when called with an array. The reason why Model.find([1,2,3]) works if say 1 and 2 are cached is because activerecord will use find_one when passed an array with 1 id which will then flow back through cache money as a single id and fetch will call add if the key is missed.
I fixed this for the simple case in 0.2.23. The more complex case I'm going to leave for later.
Try this: User.find([100,101,102]) and note in the debug log that it is UNCACHEABLE. Now, fetch the first two, individually: User.find(100); User.find(101) and then retry the original array with three values. This time it does not say uncacheable. I've been looking at the code but cannot figure out where the bug lies.
On a related note, perhaps...? This works, first time, and is cacheable, even though it boils down to the same SQL query, I know it uses a different code path: User.find(:all, :conditions=>{:id=>[300,301,302]}) while User.find([300,301,302]) does not, of course, as noted above.