I have business listings that go into classifications through a shortcuts table.
Hopefully that part is done right. The shortcuts table is almost like a standard many to many table except that it also has a region_id. I don't think I can add that third field if I use a normal m:m table.Code::has_many classifications, :through => :shortcuts
Now let's say I want to find all businesses that have shortcuts into the classification with id 3.
I can fire off that code in phpMyAdmin and get the results I want. I can always write that query in my Ruby code (defeating the purpose of my Rails associations), but I was wondering if there were a Rails way to do it, such as using the .find method. I was looking for a Business.find_by_classification method, but it's not there. It seems like this functionality has to be there somewhere.Code:SELECT * FROM businesses INNER JOIN shortcuts ON businesses.id = shortcuts.business_id WHERE shortcuts.classification_id = 3
Thanks.




Bookmarks