1

I've managed to get custom models to load before with the following code:

$model = Mage::getModel("banner/banner")
    ->getCollection()
    ->load();

But I need to now sort by an order value as well as limit the results to 6. So I wrote the following:

$home_blocks = Mage::getModel("homeblocks/homeblocks")
    ->getCollection()
    ->setOrder('order', 'ASC');
    ->setPageSize(6)
    ->setCurPage(1);
    ->load();

This however is causing werrors, specifically the following Magento error

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order ASC' at line 1

The column is defiantly called order. Adding data from the back end of magento works fine. it's just when trying to read out I'm having issues.

For reference I'm currently sticking the code directly into a custom layout file locate din the pages folder with the other default templates of my theme.

2

order is a reserved work in MySQL. Most probably the order field is not transformed into

`order`

Try to sort by a different field and see if the error reproduces. If it doesn't you may want to rename your field to something else. sort_order for example.

  • That was the issue, but now I have the problem of renaming the column. I have changed it in the database, done a find a replace in the install fields and re uploaded them, and then deleted the core_resource entry. While the numbers still display in the newly reinstalled module, the values for the sort_order no longer update. – Chris Morris Sep 19 '13 at 14:16
  • Though oddly adding anew item correctly sets the sort order... – Chris Morris Sep 19 '13 at 14:22
  • 1
    clear the cache manually even if it's disabled. Zend caches the table schema even if the cache is off. – Marius Sep 19 '13 at 14:26

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.