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

Reply via email to