I have a rather complicated relationship that I am struggling with
setting up, hopefully I can explain it so it makes sense. I will also
include what we have thus far.
I have two tables user and friends, friends is a join table that joins
users to users. In my system, friendship is bilateral, meaning to have a
friend is to be one.
I worked through the reciprocal relationship alright, but the bilateral
part has me stumped.
Here are the relevant parts of my two schema files:
User.pm
__PACKAGE__->has_many(friend => 'Takkle::Schema::Friend', 'fk_user_id');
__PACKAGE__->has_many(user => 'Takkle::Schema::Friend',
'fk_user_id_friend');
__PACKAGE__->many_to_many(user => 'friend', 'user');
Friend.pm
__PACKAGE__->table("friend");
__PACKAGE__->add_columns(
"friend_id",
{ data_type => "INT", default_value => undef, is_nullable => 0,
size => 11 },
"fk_user_id",
{ data_type => "INT", default_value => undef, is_nullable => 1,
size => 11 },
"fk_user_id_friend",
{ data_type => "INT", default_value => undef, is_nullable => 1,
size => 11 },
"message",
{
data_type => "TEXT",
default_value => undef,
is_nullable => 1,
size => 65535,
},
"status",
{ data_type => "TINYINT", default_value => undef, is_nullable =>
1, size => 1 },
"cr_date",
{
data_type => "DATETIME",
default_value => undef,
is_nullable => 1,
size => 19,
},
"apr_date",
{
data_type => "DATETIME",
default_value => undef,
is_nullable => 1,
size => 19,
},
);
__PACKAGE__->set_primary_key("friend_id");
__PACKAGE__->belongs_to(user => 'Takkle::Schema::User', 'fk_user_id');
__PACKAGE__->belongs_to(user => 'Takkle::Schema::User',
'fk_user_id_friend');
So a users friends are either the fk_user_id where fk_user_id_friend =
$user_id or fk_user_id_friend where fk_user_id = $user_id...
As you can see, currently I have only implemented the left half of this.
Any Ideas?
--
Steve Francia
Lead Developer
Takkle, Inc.
212.792.5859 (fax)
[EMAIL PROTECTED]
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/