Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collection::addAttributeToSelect() undefined method in Magento

Tags:

magento

Fatal error: Call to undefined method Desbest_Showdown_Model_Mysql4_Votes_Collection::addAttributeToSelect() in /home/desbest/public_html/clients/magentofull/app/code/local/Desbest/Showdown/controllers/IndexController.php on line 19

IndexController.php

public function voteAction(){
    $shake = Mage::getModel('showdown/votes')
        ->getCollection()
        ->addAttributeToSelect('*')
        ;
}

===============

code/local/Desbest/Showdown/Model/Mysql4/Votes/Collection.php

<?php
class Desbest_Showdown_Model_Mysql4_Votes_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('showdown/votes');
    }
}
like image 965
desbest Avatar asked Jul 13 '12 20:07

desbest


2 Answers

addAttributeToSelect() is using for EAV style model collection only (product, customer, etc.)

For other models you can use Mage_Core_Model_Resource_Db_Collection_Abstract::addFieldToSelect() method.

like image 64
Igor Sydorenko Avatar answered Oct 30 '22 04:10

Igor Sydorenko


Add this to your Collection.php

public function addAttributeToSort($attribute, $dir=’asc’) 
{ 
    if (!is_string($attribute)) { 
        return $this; 
    } 
    $this->setOrder($attribute, $dir); 
    return $this; 
}

You could also try using addFilter() or using setOrder().

Resource: This

like image 29
Sturm Avatar answered Oct 30 '22 04:10

Sturm