[Dbix-class] Re: Join Myself?

xli xli4022 at gmail.com
Mon Jul 9 19:50:39 GMT 2012


>From the manual; can you duplicate the '-ident' condition in the
example to get what you're after?

http://search.cpan.org/~arodland/DBIx-Class-0.08196/lib/DBIx/Class/Relationship/Base.pm

To specify joins which describe more than a simple equality of column
values, the custom join condition coderef syntax can be used. For
example:

  My::Schema::Artist->has_many(
    cds_80s => 'My::Schema::CD',
    sub {
      my $args = shift;

      return {
        "$args->{foreign_alias}.artist" => { -ident =>
"$args->{self_alias}.artistid" },
        "$args->{foreign_alias}.year"   => { '>', "1979", '<', "1990" },
      };
    }
  );

  ...

  $artist_rs->search_related('cds_80s')->next;

will result in the JOIN clause:

  ... FROM artist me LEFT JOIN cd cds_80s ON
        cds_80s.artist = me.artistid
    AND cds_80s.year < ?
    AND cds_80s.year > ?



More information about the DBIx-Class mailing list