Displaying 2 results from an estimated 2 matches for "have_and_belong_to_many".
2006 Jan 02
3
Selecting conditionally from HABTM
...dering whether there is a nice Rubyesque way of selecting
from a pair of HABTM models where one of them is inherited from
another object.
Here is the situation:
I have a ''posts'' table from which ''replies'' and ''articles'' are
inherited. Articles have_and_belong_to_many categories, but neither
posts nor replies do (it just does not seem to be very useful). I want
to have a page which shows (paginatedly) the articles in a selected
category. So given a category, I would like to return an array of all
of the articles associated with it.
I am no master of SQL syntax,...
2007 Mar 29
21
a better "should have valid associations"
This is pretty much the same as last time around, if you recall.
Thanks to Wilson for converting to the new form. I''ve added a few
lines. Basically, it iterates over your model associations and does
two things.
- First, just try to call the association. Usually fixes speeling
erors or other such silliness.
- Second, try to find a record with an :include on the association.
This