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
    try setOrder(new Zend_Db_Expr(cast(validity as unsigned)'), 'asc') – R T Jan 9 '17 at 10:13
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.

| improve this answer | |
3

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'));
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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