I'm down with a problem for the last one hour. I'm using EntityAPI for my custom entity.
'controller class' => 'EntityAPIController', // and i do not have an EntityClass defined
I'm using the same form for my custom entity add/edit functionality. When the values are submitted from the form, I create an entity array to pass to the entity_save function. While adding, it works like a charm. While editing, in the form submit function, I make sure to have the primary key value to the entity as well. But I get an error that says Duplicate Entry in my base table as it is trying to insert instead of update.
In an attempt to discover the error, I went to entity.controller.inc and found the save function in the controller class. The condition that separates an insert from an update is:
if (!empty($entity->{$this->idKey}) && empty($entity->is_new))
which made me realize that I need to add is_new property as well and set it to false. It still did not work. The problem seems to be with $this->idKey and when I try to see the value of this -- it is empty. The idKey property is not set.
Am I doing something wrong? Or do we need to make sure that idKey is a property of the object too? Please help.
Comments
Comment #1
mukesh.agarwal17 commentedok, so the problem is solved, and in a very weird way :-)
when calling entity_save, i was passing the entity as an array and that kinda screwed up the things. i changed it to object, and everything seems to work fine. so here you go, after a couple of hours of investment, i learn drupal_write_record, properties set by the default drupal entity controller class and how to save your entity too..
Comment #3
darrellduane commentedI found I got this same error message while looping through all of the users to update their profile information. The problem was fixed when I skipped over uid 0 and 1.