[Dbix-class] has_many LEFT JOIN with parameter
Ton Voon
tonvoon at gmail.com
Mon May 9 08:04:52 GMT 2011
On 6 May 2011, at 19:10, Justin Hunter wrote:
> Per http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Relationship/Base.pm#condition, under "To specify joins which describe more than a simple equality of column values, the custom join condition coderef syntax can be used. For example:"
>
> __PACKAGE__->has_many(
> "useraccounts", "UserAccounts"
> sub {
> my $args = shift;
>
> return {
> "$args->{foreign_alias}.userid" => { -ident => "$args->{self_alias}.id" },
> "$args->{foreign_alias}.accountid" => { '=', $value },
> };
> }
> );
>
> not sure where the join_type will go, but that should be the gist.
Thanks Justin. I wasn't aware of this functionality.
It is close, but not quite there. I think I want the example of:
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" },
};
}
);
... but where the 80s is dynamically entered at search time. Maybe something like:
$schema->resultset("Artist")->search( { name => "Elton John" }, { join => { "cds_decade" => { "-params" => [ "1979", "1990" ] } } })
Is this a useful feature? If so, I'm happy to have a go at this if someone can point where this change should be.
Ton
More information about the DBIx-Class
mailing list