[Dbix-class] Re: extra condition in join

Peter Rabbitson rabbit+dbic at rabbit.us
Wed Jul 13 07:40:17 GMT 2011


On Tue, Jul 12, 2011 at 09:47:52PM +0200, Marc Logghe wrote:
> On Tue, Jul 12, 2011 at 6:42 PM, Marc Logghe <logghe.marc at gmail.com> wrote:
> 
> > Hi,
> > I wanted to add an extra condition in a join like this:
> >
> > $lite_schema->class('Thingy')->add_relationship(
> >    "fixed_position",
> >   "Foo::Bar",
> >   { 'foreign.thingy_number' => 'self.thingy_num', 'foreign.library' => {
> > '=' => $library}},
> >   { join_type => 'left outer'}
> >   );
> >
> >
> >
> OK for the record, checked DBIC::ResultSource and it is not supported.
> However, this does the trick if the condition hash is replaced by:
> 
>   sub {
>       my $args = shift;
> 
>       return {
>         "$args->{foreign_alias}.thingy_number" => { -ident =>
> "$args->{self_alias}.thingy_num" },
>         "$args->{foreign_alias}.library"   => { '=' => $library},
>       };
>     }

Just for the sake of people landing here through search - "it" is very well
supported, and the above syntax is the official correct way to do this. This
method is not a trick, hack or in any other way inferior to the "hash"
syntax.

Cheers :)



More information about the DBIx-Class mailing list