Limit + Conditions = Confusion

Hi,

Could you please explain the :limit to me? I thought I knew what it was
but now it seems I’ve misunderstood something.

Fooditem.find_by_contents(“quark”, {:limit => 10}, {:conditions => [“origin = ?”, “fda”]}).length
=> 1

Fooditem.find_by_contents(“quark”, {:limit => 2000000}, {:conditions => [“origin = ?”, “fda”]}).length
=> 8

So is limit actually limiting the results before conditions?

Regards,

Antti

On Tue, May 08, 2007 at 05:02:40AM +0200, Antti Akonniemi wrote:

So is limit actually limiting the results before conditions?

yes, the limit option you’re using (in the first options hash) is passed
to ferret while AR conditions are applied after running the
ferret search.

To get exact results you should use :limit => :all in the first hash and
put the ‘real’ limit into the AR options hash.

Jens


Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa

Jens K. wrote:

On Tue, May 08, 2007 at 05:02:40AM +0200, Antti Akonniemi wrote:

So is limit actually limiting the results before conditions?

yes, the limit option you’re using (in the first options hash) is passed
to ferret while AR conditions are applied after running the
ferret search.

To get exact results you should use :limit => :all in the first hash and
put the ‘real’ limit into the AR options hash.

Got it working now! Thank you so much!

-antti