* Steve Francia <[EMAIL PROTECTED]> [070626 14:40]:
> in User Schema:
> __PACKAGE__->has_many(user_pictures =>'Schema::UserPicture', 'fk_user_id');
> __PACKAGE__->many_to_many(pictures => 'user_pictures', 'picture');
> 
> in UserPicture Schema:
> __PACKAGE__->belongs_to(user => 'Schema::User', 'fk_user_id');
> __PACKAGE__->belongs_to(picture => 'Schema::Picture', 'fk_picture_id');
> 
> in Picture Schema:
> __PACKAGE__->has_many(user_pictures =>'Schema::UserPicture',
> 'fk_picture_id');
> __PACKAGE__->many_to_many(users => 'user_pictures', 'user');
> 
> This is all working as designed.
> $user->pictures and $picture->users both work properly. (Yes, a picture
> can have multiple users)
> 
> What isn't working right now is:
> I would like to have a special relationship for the specific user who
> happens to also be the owner. This relationship would exist at
> $picture->owner . Ideally it would be in addition to the relationship
> already existing between a picture and it's users as the owner would be
> a part of that set as well.

I would add a user foreign key to picture and drop the owner flag from
user_picture.  The the relationship is straight forward:

In Picture Schema:
__PACKAGE__->belongs_to(owner => 'Schema::User', 'owner_id');

        -Marc

_______________________________________________
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]/

Reply via email to