5

i have magento collection

Mage::getResourceModel('customizebundles/customizebundles_collection')
                            ->distinct(true)->addFieldToSelect('validity')
                            ->setOrder('validity', 'asc');

how can i convert validity column varchar to unsigned like

SELECT DISTINCT validity FROM customize_bundles AS main_table order by cast(validity as unsigned)
1
  • 1
    try setOrder(new Zend_Db_Expr(cast(validity as unsigned)'), 'asc')
    – R T
    Jan 9, 2017 at 10:13

2 Answers 2

5
Mage::getResourceModel('customizebundles/customizebundles_collection')
      ->distinct(true)->addFieldToSelect('validity')
      ->setOrder(new Zend_Db_Expr('cast(validity as unsigned)'), 'asc');

using Zend_Db_Expr will get you the solution.

4

you can set cast as mention @RT

$collection->setOrder(new Zend_Db_Expr("cast(validity as unsigned)"), 'asc')

or

 $collection->select()->order(new Zend_Db_Expr("CAST(validity AS unsigned )",'asc'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.