[Dbix-class] RestrictWithObject and ResultSet
Guillermo Roditi
groditi at gmail.com
Tue Mar 4 16:09:39 GMT 2008
sub restrict_Foo_resultset {
my ($self, $fullset) = @_;
my $keys = [ keys %{ $self->{hash} } ];
my $restricted = $fullset->search({ id => {'-in' => $keys } });
return $restricted;
}
--Guillermo Roditi (groditi)
On Mon, Mar 3, 2008 at 9:00 PM, James R. Leu <jleu at mindspring.com> wrote:
> 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
>
> _______________________________________________
> 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.rawmode.org
>
More information about the DBIx-Class
mailing list