Saurav Arya Saurav Arya - 1 year ago 81
PHP Question

Escape from CakePHP Paginate condition

Paginate query:

$this->paginate = array(
'conditions' => array(
// 'Product.soft_delete NOT' => 'on',
// 'Product.product_status NOT' => 'inactive',
// $conditions
'Product.original_price <=' => 77
),
'recursive' => 2,
// 'order' => $sort_by,
'paramType' => 'querystring',
'limit' => '25',
'maxLimit' => 100,
);
$records = $this->paginate('Product');


CakePHP adding single quote to original_price
77
so it is creating problems in number comparison.

Cakephp query output:

............LEFT JOIN `admin_mytab`.`seller_categories` AS `Seller_3` ON (`Product`.`seller_3` = `Seller_3`.`id`) WHERE `Product`.`original_price` <= '77' LIMIT 25


MySQL
original_price
is
varchar
field.
77
in quotes unable to compare with mysql field.

Any help would be appreciated.

Answer Source

Try writing it like this:

$this->paginate = array(
    'conditions' => array(
        'Product.original_price <= 77'
    ),
    'recursive' => 2,
    'paramType' => 'querystring',
    'limit' => '25',
    'maxLimit' => 100,
);
$records = $this->paginate('Product');

Instead of key => value just use value. But usually it doesn't matter if number is enclosed with quotes, even with varchar.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download