4

If you have a model, normally there should be a resource model and a resource collection too, but there are some core models where this is not the case.

Example: Mage_Log_Model_Customer

I tried to answer another question and thought its possible to get data from this models collection directly ...

$model = Mage::getModel('log/customer')->getCollection();
foreach ($model as $item) {
    var_dump($item->getData());
}

But it doesn't work ...

$model = Mage::getModel('log/customer');
var_dump(get_class_methods($model));

.... gives valid output like ...

array (size=54)
  ...
  7 => string 'getCollection' (length=13)
  ...

Okay so far, but doing ...

$model = Mage::getModel('log/customer')->getCollection();
var_dump(get_class_methods($model));

... just returns null. Reason for this is, there is no Mage_Log_Model_Resource_Customer_Collection.

Adding this file there ...

class Mage_Log_Model_Resource_Customer_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
    protected function _construct()
    {
        $this->_init('log/customer');
    }
}

... gives access to this DB table.

Is there any reason for not adding "Resource Collection" classes for some models? Anything that could break Magento? Just forgot to add these files?

1 Answer 1

1

A missing resource collection model is not the same as a missing resource model.
I don't have an answer to why this is missing, I can just assume that in the core there was no need for a collection resource model for the Mage_Log_Model_Customer.
The log module is used just to log the customer activity and to be able to see when the customer last logged in.
There is no case when you need the full collection of logs.

1
  • Still think there should be a resource (collection) models too ... used or not.
    – sv3n
    Commented Feb 5, 2018 at 23:57

Your Answer

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

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