[Dbix-class] Relationship to the same table

Peter Rabbitson rabbit+dbic at rabbit.us
Tue Jan 5 05:59:03 GMT 2010


Pavel O. Karoukin wrote:
> Hello,
> 
> in table "things" i am storing values for each "thing" and it's "type".
> What I want to achieve - select all "thing"s which has different type
> from current one:
> 
> my $things = $schema->resultset("Thing")->first()->different_things();
> 
> I am trying to define this as relationship, but from code seems like
> $cond in has_many() can accept only foreign and self fieldnames and
> that's all. No conditions. It's possible to set conditions in %attr, but
> this is something different.
> 
> So how it's possible to create relationship to the same table?
> 
> (I always can rewrite this with subqueries, but this is really join and
> if this is possible I'd like to use it as a joins/relationships)
> 

This is not yet possible. The light at the end of the tunnel is present,
but the tuits are scarce. For the time being your best bet is a
virtual view:

http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSource/View.pm



More information about the DBIx-Class mailing list