[Dbix-class] Excluding columns from a query

Nick Wellnhofer wellnhofer at aevum.de
Fri Feb 12 12:16:16 GMT 2010

On 12.02.2010 04:49, Rob Kinyon wrote:
> On Thu, Feb 11, 2010 at 17:24, Darren Duncan <darren at darrenduncan.net> wrote:
>> Nick Wellnhofer wrote:
>>> If I want to exclude a single column from a query I currently have to list
>>> all columns except the one to be excluded in the 'columns' attribute. This
>>> is cumbersone and AFAICS doesn't work with prefetch. It would be nice if I
>>> could simply pass a list of all the columns I want to be excluded including
>>> prefetched ones.
>>> Or am I missing something?
>> I don't know if you can do that, but it is certainly a very reasonable thing
>> to want to do. -- Darren Duncan
> my $rs2 = $rs->search(
>     undef,
>     {
>         columns => [ grep { $_ ne 'exclude_me' } $rs->resultsource->columns ]
>     }
> );

Thanks for the tip. I keep forgetting about the usefulness of the grep
function. But that doesn't work with prefetch. I think something like
this would be handy:

        prefetch => 'related',
        exclude  => [ 'me.exclude_me', 'related.exclude_me_too' ],

> You can also exclude them at the ResultSet level - I leave finding out
> how as an exercise for the reader.

What do you mean? Overriding the search method?


More information about the DBIx-Class mailing list