# Problem (with fix?) for passing :multi =\> \[ \]

**URL:** <https://www.ruby-forum.com/t/problem-with-fix-for-passing-multi/124894>\
**Category:** Ferret\
**Created:** [January 3, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/problem-with-fix-for-passing-multi/124894 "2008-01-03T16:22:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [January 3, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/problem-with-fix-for-passing-multi/124894/1 "2008-01-03T16:22:21Z")

</div>

I’m using acts\_as\_ferret, passing through multiple classes using :multi  
and also some conditions. The way i’m doing this, which seems a bit  
dirty (but it’s the only way i can work out) is to call find\_by\_contents  
on the first element in an array of classes (called ‘classes’ here), and  
then point :multi at the rest of the array of classes:

@search\_results = classes.first.find\_by\_contents(@search.term,  
#(ferret) options  
{:page =\> (params[:page] || 1),  
:per\_page =\> 10,  
:multi =\> classes.slice(1, classes.length) },  
#find\_options  
{:conditions =\> [“id = ?”, 99]}  
)

However, if classes has only one class in it, then :multi points to an  
empty array, which seems to confuse the find\_by\_contents method - for  
example, when doing a search on a single class, with a condition that  
should return 1 result, ‘total\_hits’ equals 1 but @search\_results is  
empty.

Following the code through method calls in the class\_methods file in  
acts\_as\_ferret, it seems that having a value for :multi but not having  
any classes in it causes some confusion.

To get around this, i added the following line at the start of the  
find\_with\_ferret method (which is an alias for find\_by\_contents) -

options.delete :multi if options[:multi] == []

This removes the confusion and everything’s fine as far as i can tell.  
My question is this - should what i’ve done be considered a bug fix for  
find\_with\_ferret, or is the fault mine for sometimes pointing :multi at  
an empty array in my call?

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [January 3, 2008, 8:53pm UTC](https://www.ruby-forum.com/t/problem-with-fix-for-passing-multi/124894/2 "2008-01-03T20:53:48Z")

</div>

Max, seems to me that your code would help to make things more robust,  
if it’s a public API then it should stand up to a little abuse in ways  
not intended. maybe more of an enhancement than a bug fix, but a fix  
just the same.

Max W. wrote:

> I’m using acts\_as\_ferret, passing through multiple classes using :multi  
> and also some conditions. The way i’m doing this, which seems a bit  
> dirty (but it’s the only way i can work out) is to call find\_by\_contents  
> on the first element in an array of classes (called ‘classes’ here), and  
> then point :multi at the rest of the array of classes:
> 
> @search\_results = classes.first.find\_by\_contents(@search.term,  
> #(ferret) options  
> {:page =\> (params[:page] || 1),  
> :per\_page =\> 10,  
> :multi =\> classes.slice(1, classes.length) },  
> #find\_options  
> {:conditions =\> [“id = ?”, 99]}  
> )
> 
> However, if classes has only one class in it, then :multi points to an  
> empty array, which seems to confuse the find\_by\_contents method - for  
> example, when doing a search on a single class, with a condition that  
> should return 1 result, ‘total\_hits’ equals 1 but @search\_results is  
> empty.
> 
> Following the code through method calls in the class\_methods file in  
> acts\_as\_ferret, it seems that having a value for :multi but not having  
> any classes in it causes some confusion.
> 
> To get around this, i added the following line at the start of the  
> find\_with\_ferret method (which is an alias for find\_by\_contents) -
> 
> options.delete :multi if options[:multi] == []
> 
> This removes the confusion and everything’s fine as far as i can tell.  
> My question is this - should what i’ve done be considered a bug fix for  
> find\_with\_ferret, or is the fault mine for sometimes pointing :multi at  
> an empty array in my call?
