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.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/             http://www.shadowcatsystems.co.uk/ 

_______________________________________________
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