Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine: How to mark object column value as dirty?

Tags:

php

doctrine

I have a column of type object in a model. But if I load a model, and change a property of the object, and then re-save, it doesn't seem re-serialize the object. e.g.

$model_instance = $table->find(1);
$object = $model_instance->object_column;
$object->someProp = 'new value';
$model_instance->save(); //has no effect

I think this is because it is checking for modification by comparing the old and new values using !==, which returns false because they are both references to the same object.

I could clone the object before saving but there clearly must be a more obvious way which I have missed.

like image 344
Tom Haigh Avatar asked Oct 15 '22 00:10

Tom Haigh


1 Answers

State is not changed because you don't update the field (just the reference). If you're interested how it happens read set() and _set() methods in Doctrine_Record class.

You can manually change the state of a record with a state() method:

$model_instance->state(Doctrine_Record::STATE_DIRTY);

This should force save() to persist your changes.

like image 173
Jakub Zalas Avatar answered Oct 21 '22 06:10

Jakub Zalas