novaprospekt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Aug-22 14:22 UTC
[Rails] Re: Problem with find condition and habtm relationship.
Hey, thanks very much for the help. Since posting I found my solution:
def self.find_by_feature(feature_ids, sort)
return [] if feature_ids.empty?
feature_ids = feature_ids.flatten
find(:all, :readonly => false,
:joins => "INNER JOIN features_restaurants a ON restaurants.id
= a.restaurant_id",
:conditions => ["a.feature_id IN (?)", feature_ids],
:group => "restaurants.id HAVING COUNT(restaurants.id)
#{feature_ids.size}")
end
Seems to work fine. I think I made an slight error describing what
exactly I wanted to achieve. What this code achieves is displaying
restaurants that include every checked box which I believe is more
desirable behaviour.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---