1

I have created a module and EAV tables for that. Module's tables are very similar to customer_Address entity and i have defined Attribute AttrA, AttrB and AttrC for this table.

So table structure is very similar to as follows:

+------------------+----------------------+------+-----+---------------------+----------------+
| Field            | Type                 | Null | Key | Default             | Extra          |
+------------------+----------------------+------+-----+---------------------+----------------+
| entity_id        | int(10) unsigned     | NO   | PRI | NULL                | auto_increment |
| entity_type_id   | smallint(5) unsigned | NO   |     | 0                   |                |
| attribute_set_id | smallint(5) unsigned | NO   |     | 0                   |                |
| increment_id     | varchar(50)          | YES  |     | NULL                |                |
| parent_id        | int(10) unsigned     | YES  | MUL | NULL                |                |
| created_at       | timestamp            | NO   |     | 0000-00-00 00:00:00 |                |
| updated_at       | timestamp            | NO   |     | 0000-00-00 00:00:00 |                |
| is_active        | smallint(5) unsigned | NO   |     | 1                   |                |
+------------------+----------------------+------+-----+---------------------+----------------+

and AttrA, AttrB and AttrC values are stored in tables with respective data type.

Now using the basic syntax, I am able to add value of attributes AttrA, AttrB and AttrC. Which is:

$model = Mage::getModel('customer/address');
$model->setAttrA('ValA')->setAttrB('ValB')->setAttrC('ValC');

doing this correctly sets the values of AttrA, AttrB and AttrC but value of parent_id in customer_entity sets to NULL by default.

Here I want to be able to set the parent_id to some other value.

For this i tried suggestion given in different post using setParentId(<parent-id-value>). Which is not working in my case. Any idea how i can do this?

  • This should do. Did you clean the cache? Zend_Db caches the table structure to know what can be written to the table - so rm -rf on the directory helps – Fabian Blechschmidt Jun 10 '14 at 18:09
  • @FabianBlechschmidt I have disabled cache in my Magento setup. – Lalit Jun 11 '14 at 4:38
  • 1
    You can't disable the Zend_Db cache. – Fabian Blechschmidt Jun 11 '14 at 10:25
1

Even if parent_id is a column in the main table, you still need it as an attribute in the eav_attribute table.
Just create one attribute called parent_id (the same as the column) with the backend_type "static".

This is how it works for the sku attribute for products.

0

You might also want to try $model->setData('parent_id', $value); and as a personal opinion i would double/triple check you are saving the object correctly.

  • Tried this as well. Also, printed $model->getData() before $model->save(). Which returns Array ( [parent_id] => 22 [name] => test name ) Is this how it should look? – Lalit Jun 11 '14 at 4:49
  • Yes, dump the var again to see how does it looks after save() and check the db to see if info is stored. – mbalparda Jun 11 '14 at 11:00

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.