I've had a look through the AAF source and can't see why this isn't
working. It seems to accept a condition and apply it to the
activerecord find but it's simply not happening. Even if I set a
condition that would normally cause an error, the error isn't occuring
so I'm a little stumped here. Would really appreciate any suggestions!
I've had a look through the AAF source and can't see why this isn't
working. It seems to accept a condition and apply it to the
activerecord find but it's simply not happening. Even if I set a
condition that would normally cause an error, the error isn't occuring
so I'm a little stumped here. Would really appreciate any suggestions!
The parameters are the query itself (string or Ferret query), options (hash) for ferret and find_options (hash) for AR. What you are passing is string and a single hash that is going to the ferret options instead of AR. Try this:
Besides, the find_options is to include other related objects (eg. {:include => :suplier_category}) and not to filter the results. You need to handle filtering of results through the ferret query or process the results yourself.
Many thanks for the help. I was thinking it was a reasonable thing to do of using the activerecord “condition” to further filter a search. Is there a reason I shouldn’t use this approach? Essentially I’ve got a couple of drop down menus (for area and category), which I was going to set in the condition and then a free text search for anything more specific. Is this not the best way of going about it?
The problem with your approach is that it doesn’t work with how acts_as_ferret (AAF) works. What AAF does is first gets ids of records matching your query and then goes one by one doing ModelXyz.find n (n being the id) with the find options you sent grouping all those results into an array and returning it. So, you can try using your conditions but it might break or return an array with some empty slots. In my case I had some requirements that made me do my own find_by_contents (I named it ferret_find) based on find_by_contents. That way I learned exactly how it works and adapted it for my needs.