if ($animal and $animal->save()) { // Extending Model with XML-Data $animal = Model_Animal::forge($animal->to_array())->set(array( 'xml' => Format::forge($animal)->to_xml(), )); $animal->save();
but then I receive an error, that I try to add an object with the same ID, which is correct. As I cannot do something like update() there I have no idea how to handle that.
Can someone please let me know, how can this be done? I read about observers but don't know how to handle them. Also I tried to do this in post_save() in the model without any luck.
I'm not sure what you're trying to do here. Why would you forge a new object if you want to update an existing one? Any why save an object, and then create a new one in which you save an xml version of itself? It all looks very complicated an unneeded.
But why not simply use
if ($animal and $animal->save()) { // Extending Model with XML-Data $animal->xml = Format::forge($animal)->to_xml(); $animal->save(); }