[Dbix-class] Chained resultsets and WHERE operators
Mike Raynham
catalyst at mikeraynham.co.uk
Tue Nov 9 13:54:06 GMT 2010
On 09/11/10 13:49, Steve wrote:
> It appears that you are *not* chaining these resultsets...
>
> If you first do...
> # Narrow the search down if the start date is supplied.
> $date_ranges = $rs->search({
> start_date => { '<=', $start_date },
> end_date => { '>=', $start_date },
> }) if $start_date;
>
> then in order to 'chain' you must...
>
> $date_ranges = $date_ranges->search({...
>
> You overwrote your resultset when you...
>
> # Narrow the search down if the end date is supplied.
> $date_ranges = $rs->search({
> start_date => { '<=', $end_date },
> end_date => { '>=', $end_date },
> }) if $end_date;
Sorry, that was my mistake when reducing my original code down for the
email. You are right - it should have read:
###
# Create a search.
my $date_ranges = $rs->search({});
# Narrow the search down if the start date is supplied.
$date_ranges = $date_ranges->search({
start_date => { '<=', $start_date },
end_date => { '>=', $start_date },
}) if $start_date;
# Narrow the search down if the end date is supplied.
$date_ranges = $date_ranges->search({
start_date => { '<=', $end_date },
end_date => { '>=', $end_date },
}) if $end_date;
###
More information about the DBIx-Class
mailing list