Ok, David says on page 241 that sometimes a many-to-many relation with
attributes are better implemented as an actual model instead of using
HABTM.
Well, I’ve got that situation and I can’t figure it out.
All of the examples in the book have HABTM examples between 2 different
tables, but I want to have a HABTM relation on 1 table with itself.
(e.g.,
if I have a table Things, then I would like one “Thing” to “helpout”
another
Thing)
Table 1: “Thing”
Column: Name
Table2: “Helps”
Column: thing_id (e.g. “this thing.”)
Column: helps_id (. “helps that thing”)
It seems like I might want to use a HABTM, but I can’t figure out the
settings.
OR (and I think this is what I actually need / want to do), I need a
separate model to represent Helps which has some belongs_to / has_many
relationships in it (I think this is better because then I could do some
interesting complex reporting on the “Helps” table, such as “who helps
the
most number of other things?”).
Any ideas how to set this up in the Models? And, what would be the right
way
to say:
thing1.helps << thing2 (i.e. we need to document the fact that thing1
helps
thing2)?
Thanks,
-Greg
Greg E.
CTO, Eyetools Inc.
[email protected] mailto:[email protected]
(916) 792 4538