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


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to