Say I have a method in my base class shared by all resultset classes to add
an id onto a resultset criteria.

package ::Resultset;

sub limit_by_id {
    my ( $rs, $id ) = @_;
    return $rs->search( { 'me.id' => $id } );
}

Now, I could do this:

$rs = $schema->resultset( 'Track' )->limit_by_id( 1234 );


But, the following won't work because the alias is wrong (should be '
tracks.id' => $id):

$cd_rs = $schema->resultset( 'Cd' )->search( 'me.id' => 4321 );
$rs = $cd_rs->search_related( 'tracks' )->limit_by_id( 1234 );


Would it be safe to use the resultset's current alias?

sub limit_by_id {
    my ($rs , $id ) = @_;

    my $alias = $rs->{attrs}{alias};
    return $rs->search({ "$alias.id" => $id } );
}



-- 
Bill Moseley
[email protected]
_______________________________________________
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/[email protected]

Reply via email to