Hi,

first of all, the include options should be a simple Array of Symbols,
or, if you only want to include one relationship, a single Symbol,
like

:include => [ :media_files ]
or
:include => :media_files

And yes, aaf will filter these includes for each model.

Second, aaf unfortunately does not support specifying conditions on a
per model basis yet, so the sql resulting from your conditions argument
has to be valid for fetching records from each of the models you query -
in short, only use attributes present in all of the models.

Afair there's already a trac ticket regarding the implementation of
per-model conditions for multi search, but I didn't find the time to
implement this yet. I'll try to have a look into this over the weekend.


Cheers,
Jens

On Thu, Dec 13, 2007 at 03:28:09PM -0500, Jean-Charles Carelli wrote:
> Hello, I'm using find_with_ferret to search multiple models and it  
> works great. The trouble is I need to filter the results  
> using :include and :conditions.
> 
> I get two errors depending on the syntax I use in the search. Reading  
> the source, I see the retrieve_records method seems to filter  
> the :include and :conditions so that they only apply to the relevant  
> model when searching multiple models. This is exactly what I want, but  
> I can't seem to get it to work.
> 
> My question: is my syntax wrong? Or have I misread how retrieve_record  
> works? If so, How would I apply conditions to a subset of models being  
> searched in a multi model search?
> 
> # First Try. This syntax with using a hash to contain the include  
> params works with regular active_record calls.
>       @results = Inventory.find_with_ferret( @query,
>                                            { :multi => [ Artist], :page => 
>                                            params[ :page ], :per_page  => 10 
> },
>                                            { :include => {:media_files => 
>                                            {}}, :conditions =>  [ 
> "media_files.file and inventories.status = 
> 'donated'" ] } )
>       
> 
> 
> # Resulting Error
> undefined method `to_sym' for [:media_files, {}]:Array
> 
> 
> # Second try. I put the :include params in [] array brackets to see if  
> that would help the to_sym error. That fixes the to_sym error. But now  
> the association isn't getting found?
>       @results = Inventory.find_with_ferret( @query,
>                                            { :multi =>  
> [ Artist], :page => params[ :page ], :per_page => 10 },
>                                            { :include =>  
> [:media_files => {}], :conditions => [ "media_files.file and  
> inventories.status = 'donated'" ] } )
> 
> # Resulting Error
> Association named 'media_files' was not found; perhaps you misspelled  
> it?
> 
> 
> Thanks in advance.
> 
> J-C
> 

> _______________________________________________
> Ferret-talk mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/ferret-talk

-- 
Jens Krämer
http://www.jkraemer.net/ - Blog
http://www.omdb.org/     - The new free film database
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to