DBIx :: Class :: ResultSet Issues

I have the following code:

package MyPackage::ResultSet::Case; use base 'DBIx::Class::ResultSet'; sub cases_last_fourteen_days { my ($self, $username) = @_; return $self->search({ username => $username, date => { '>=' => 'DATE_SUB(CURDATE(),INTERVAL 14 DAY)' }, }); }; 

But when I try to use it like this:

 $schema->resultset('Case')->cases_last_fourteen_days($username) 

I always get zero results, can anyone tell me what I'm doing wrong?

Thanks!

+4
source share
1 answer

How you use the SQL :: Abstract clause will result in this when the clause:

 WHERE username = ? AND date >= 'DATE_SUB(CURDATE(),INTERVAL 14 DAY)' 

If you want to use the database functions in the where clause, you need to use a scalar link , for example:

 date => { '>=' => \'DATE_SUB(CURDATE(),INTERVAL 14 DAY)' }, 

ProTip : if you set the DBIC_TRACE environment DBIC_TRACE to 1, DBIx :: Class will print the queries that it generates in STDERR ... so you can check if this really does what you want.

+13
source

All Articles