On Mar 5, 2010, at 6:13 PM, Jack Cole wrote:
I've tried this two ways. Method #1 was using the 'has_many :x through
=> :x-assignments' (as was shown in the Rapid Rails with Hobo book,
Tut 8, "Model Relationships, Pt II), which worked - sort of. I was
able to add actors to the film record, and films to actor records, but
the relationships didn't reflect in both record sets. I could set it
manually through SQL statements, but otherwise there was no way to do
it through the app itself.
As an example, I was able to add "Plan 9 from Outer Space" and could
select "Tor Johnson" as an actor for that film, but when I went to Tor
Johnson's actor record, it didn't show "Plan 9 from Outer Space" as a
film he was in. I'm assuming because the two different transactions
updated two different index tables (film_assignments and
actor_assignments).
Almost had it - the trick is that the join table is shared. So it
looks something like this:
class Actor
has_many :actor_assignments
has_many :films, :through => :actor_assignments
end
class ActorAssignment
belongs_to :actor
belongs_to :film
end
class Film
has_many :actor_assignments
has_many :actors, :through => :actor_assignemnts
end
(various other noise, like :accessible and :dependent => :destory
elided for clarity)
In this case, you also gain a handy place to attach relevant details
related to the (actor, film) pairing - for instance, the character's
name, etc. HABTM hasn't (since Rails 2.3) supported that sort of thing.
Hope this helps!
--Matt Jones
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.