[Dbix-class] Extended JOIN syntax
Bernhard Graf
dbic4 at augensalat.de
Sun Jan 29 21:49:52 GMT 2012
Am 29.01.2012 21:52, schrieb Peter Rabbitson:
> It is possible, but is not yet particularly pretty. The trick is
> that the coderef in question is called every time the relationship
> needs to be resolved. By referencing some external package-global
> you can control what the coderef will return.
like this?
__PACKAGE__->mk_group_accessors(inherited => qw(era_begin era_end));
My::Schema::Artist->has_many(
cds_era => 'My::Schema::CD',
sub {
my $args = shift;
return {
"$args->{foreign_alias}.artist" => { -ident =>
"$args->{self_alias}.artistid" },
"$args->{foreign_alias}.year" => {
'>', __PACKAGE__->era_begin,
'<', __PACKAGE__->era_end,
},
};
}
);
...
$artist_rs->era_begin(1979);
$artist_rs->era_end(1990);
$artist_rs->search_related('cds_era')->next;
Bernhard
More information about the DBIx-Class
mailing list