Joshua Muheim wrote:
I got the following class:
class Member < ActiveRecord::Base
:class_name => 'Member',
:join_table => 'members_have_buddies',
:foreign_key => 'member_id',
:association_foreign_key => 'buddy_id'
You can see that a member can have any other member as a "buddy"; these
relationships are held in the table members_have_buddies (member_id,
So far, so good.
I have a member "my_member", that has 3 other members marked as buddies,
so I got 3 entries in the members_have_buddies table.
When I delete my_member, then the 3 entries in the table are also
deleted, as I expect it to do.
But when I delete one of the 3 other members, that are marked as
members, then the related entry in the members_have_buddies table does
*not* get deleted!
I assume, this is an error, is it? Or have I done anything wrong? How
can I solve this problem?
Thanks a lot for help.
I know you posted this while back, but I'm having a great deal of
trouble with my habtm self-referencing setup and was wondering if you
could help. I have the exact same set up as what you showed in your
The problem I run into is that it seems the DB only saves in one
direction, so if I make memberA have buddies memberB & memberC, when I
call memberA.friends I get both memberB & memberC returned. However if I
do memberB.friends I get no return. Same thing for memberC.friends.
And since the db only saves uni-directionally, it's not letting me
assign the other way around and make memberA a buddy under memberB or C.
Any suggestions on how to address this and make it so I can store and
retrieve accurate friend connections?