I don't think we are on the same page. Permit me to clarify.

Allow me to illustrate the tables and relationships:

picture
+ picture_id
+ lots of other fields of no importance here

user_picture
+ user_picture_id
+ fk_picture_id
+ fk_user_id
+ owner (either 1 or 0)

user
+ user_id
+ lots of other fields of no importance here

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 kinda see how proxy could fit that need, but some of the other answers
you provided made me think I didn't explain myself properly the first time.
I though a has_one would do it, but more and more that doesn't seem to
be the case.
-Steve

Matt S Trout wrote:
> On Tue, Jun 26, 2007 at 01:14:17PM -0400, Steve Francia wrote:
>   
>> In my database I have three tables user, picture and user_picture.
>> They are setup with many to many relationships and work great.
>>
>> The user_picture table also has an extra field, owner (bit), which
>> designates the original uploader.
>>
>> What I would like to have is a has_one relationship that joins picture
>> to user through the user_picture table where owner = 1.
>>     
>
> It's a foreign key, so it's a belongs_to, not a has_one.
>
>   
>> so $video->owner would be the user object.
>>
>> In that way it would work similarly to the many_to_many convenience
>> relationships.
>>     
>
> For this, I'd has_many across to user_picture, have it prefetch the picture
> and owner objects, and then have the UserPicture object proxy all the picture
> methods (there's a rel attr to do this for you). Then you can treat the
> UserPicture object as a Picture object for most purposes but $up->owner will
> work normally.
>
>   

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

Reply via email to