> ActiveRecord does that automagically for you if you pass it an array.
Awesome!
Richard,
I think I have a better understanding of what you are wanting now.
It''s
a difficult problem, but let''s see if this is a step in the right
direction.
If we could get a count of the features matched per restaurant, then we
could rank the restaurants by number of matches. If the number of
matches equals the feature count specified, then we have a 100% match.
Let''s do this in SQL:
Product.find_by_sql(
["SELECT
count(restaurants.id) AS num_matched,
restaurants.*
FROM restaurants
INNER JOIN features_restaurants ON (restaurants.id
features_restaurants.restaurant_id)
WHERE
features_restaurants.features_id IN (?)
GROUP BY
restaurants.id
ORDER BY
num_matched desc", feature_ids])
The num_matched field would contain the number of features matched per
restaurant. You could then show closest matches first and even
calculate a percentage with num_matched/feature_ids.size. Or, if you
are only interested in the 100% matches, you can adding a HAVING clause
between the group by and order by:
HAVING
count(restaurants.id) = #{feature_ids.size.to_s}
Try this and see how it works for you.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---