[Dbix-class] user/friendship many-to-many relationship

Tobias Kremer list at funkreich.de
Tue Apr 24 19:10:11 GMT 2007


>> I'd suggest to use a symmetric table schema with columns like  
>> userA and
>> userB.
>> And if there is a new friendship insert twice: (112, 45) and (45,  
>> 112).
>> Makes friends-of-friends queries easier and faster.
>
> Expanding on that theme, I'd take a slightly different approach.
> I would create a view:

Nice idea - unfortunately I'm bound to using MySQL 4.x for now :(

> If you add a trigger to the friendship table that normalizes inserts,
> for instance inserting the lowest id of a pair as user_id and the  
> higher
> id as friend_user_id, that would ensure relationships don't  
> inadvertently
> get added twice (e.g., (1,2), (2,1)).

But then you won't be able to tell who requested the friendship and who
received the request. The good thing is, that this could be done without
database triggers by overwriting DBIx::Class's insert method.

--Tobias

_______________________________________/\____ _ .  .
+ web ::::::: http://www.funkreich.de
+ last.fm ::: http://www.last.fm/user/soulchild77
----------------------------------------------- -- -  -






More information about the Dbix-class mailing list