I've added to the customer_entity
table a new column called source
that I want to maintain through an admin form. This means I'll be working with the customer model to update that value; however, I've learned that it doesn't work that way with EAV models. So I can't call $model->setData('source')->save()
because that value is not stored on an attribute table.
You might ask, "why not store it as an attribute?" There are a couple of reasons. Most importantly, I'm joining table data via resource adapters for a report. I was looking to write a "universal select" query that reads from both _entity
tables and those serving simpler models.
So here's my problem:
When making changes to an EAV model in Magento, the abstract method Mage_Eav_Model_Entity_Abstract::walkAttributes
gets triggered through the _afterSave
method. As I understand it, this will call any registered backend models for handling CRUD operations.
I don't want this to happen. In my case, I'm working with the Mage_Customer_Model_Entity_Customer
resource model. I'm calling its write adapter to manually execute an UPDATE
query to maintain that source
value. But it seems to be triggering a call to save addresses attached to that customer. This appears to be triggered as a result of those registered backend models on the customer attributes:
Mycompany_Customer_Model_Entity_Customer {
...
public function setSource($customerId,$source=null) {
$data=array(
'entity_id' => $customerId,
'source' => $source
);
Mage::getSingleton('core/resource')->getConnection('core_write')
->query("UPDATE `{$this->getEntityTable()}` SET `source`=? WHERE `entity_id`=?",$data);
}
...
}
Why does this trigger attribute walking? How can I prevent this?