# Limit + Conditions = Confusion

**URL:** <https://www.ruby-forum.com/t/limit-conditions-confusion/103586>\
**Category:** Ferret\
**Created:** [May 8, 2007, 5:02am UTC](https://www.ruby-forum.com/t/limit-conditions-confusion/103586 "2007-05-08T05:02:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antti\_Akonniemi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@Antti\_Akonniemi](https://www.ruby-forum.com/u/Antti_Akonniemi)\
**Post date:** [May 8, 2007, 5:02am UTC](https://www.ruby-forum.com/t/limit-conditions-confusion/103586/1 "2007-05-08T05:02:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Antti\_Akonniemi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@Antti\_Akonniemi](https://www.ruby-forum.com/u/Antti_Akonniemi)\
**Post date:** [May 8, 2007, 9:54am UTC](https://www.ruby-forum.com/t/limit-conditions-confusion/103586/2 "2007-05-08T09:54:56Z")

</div>

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  
removed\_email\_address@domain.invalid | [www.webit.de](http://www.webit.de)

Amtsgericht Dresden | HRB 15422  
GF Sven Haubold, Hagen Malessa

---

<div class="post-metadata">

**Author:** ![Antti\_Akonniemi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@Antti\_Akonniemi](https://www.ruby-forum.com/u/Antti_Akonniemi)\
**Post date:** [May 8, 2007, 1:20pm UTC](https://www.ruby-forum.com/t/limit-conditions-confusion/103586/3 "2007-05-08T13:20:08Z")

</div>

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
