Search code examples
magentomagento-1.9

Remove Field From Collection


How can I remove a field from a collection?

I found the method removeFieldFromSelect() in Mage_Core_Model_Resource_Db_Collection_Abstract, but it does not seems to work.

I tried:

$collection = Mage::getModel('bannermanagement/banner')->getCollection();
$collection->removeFieldFromSelect('status');

but still the field shows up. How can I remove the field Status from collection?


Solution

  • I checked that removeFieldFromSelect is available in Magento, but it not used anywhere. However, you can achieve it like this:

    Clone your Collection in your custom module Collection file

    $idsSelect = clone $this->getSelect();

    and then reset the Columns

    $idsSelect->reset(Zend_Db_Select::COLUMNS);

    and then set the columns again

    $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table');