[Dbix-class] Multiple belongs_to relationships referencing same class

Brandon Black blblack at gmail.com
Wed Apr 25 23:42:44 GMT 2007


On 4/25/07, Tobias Kremer <list at funkreich.de> wrote:
> Am 25.04.2007 um 23:10 schrieb Brandon Black:
> > On 4/25/07, Tobias Kremer <list at funkreich.de> wrote:
> >> Sounds like my kind of problem - what are the alternatives to proxy?
> >
> > One alternative to proxy is just to not use proxy.  Proxy is merely
> > convenience.  Instead of saying $user_relation_object->username (which
> > is ambiguous given your duplicate proxy statements), say
> > $user_relation_object->requestor->username or
> > $user_relation_object->receiver->username.
>
> Yeah, but that's exactly what I want to avoid. If somebody does
> $user->confirmed_friendships, he/she is not supposed to know who
> initiated the friendship (requestor or receiver). All he/she wants
> is a list of User objects (except $user) which are friends of $user.
> The same goes for the other two methods. Currently I can't see a
> sane way to accomplish this with DBIx::Class :(
>

Follow the advice from the other thread (make a view that unions the
table with itself, if possible use insert/update triggers to re-order
the two generic user columns in a consistent manner (and if doing
that, then add a third field for who initiated it)), and then add that
view to your schema with a relationship to user so that you can query
it.

-- Brandon



More information about the Dbix-class mailing list