[Dbix-class] RestrictWithObject and ResultSet

James R. Leu jleu at mindspring.com
Tue Mar 4 02:00:14 GMT 2008


Hello,

I'm trying to use RestrictWithObject in my Catalyst app
to filter all of the results of queries to my Model by
checking if their keys are in hash that I put inside the
'Restricting Object'.  I've successfully gotten the
'restrict_Foo_resultset' to be called, but I'm stuck
when trying to build a result set to return.

I have some logic that sift through each row if the $fullset
and then tries to build a new $filterset to return.  No matter
how I build the $filterset, the app is getting access
to all of the rows in the $fullset.

Here is a my latest attempt at the restricting method:

sub restrict_Foo_resultset {
    my $self = shift;
    my $fullset = shift;
    my $class = $fullset->result_class();

    my @all;
    while (my $item = $fullset->next()) {
        if (defined($self->{hash}->{$item->id()})) {
            push(@all, $item);
        }
    }

    $fullset->reset();
    $fullset->set_cache([@all]);
    return $fullset;
}

I've also tried:

    $fullset->set_cache([@all]);
    return $fullset->search_rs();

Any pointers on the correct way to do this?

-- 
James R. Leu
jleu at mindspring.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080303/84f3647a/attachment.pgp


More information about the DBIx-Class mailing list