I am trying to use do the most simple update query but Doctrine issues an INSERT statement instead of an UPDATE.
$q = Doctrine_Query::create()
->from('Image i')
->where('id = ?');
$image = $q->fetchOne($articleId, Doctrine_Core::HYDRATE_RECORD);
$image->copyright = "some text";
$image->save();
I have also tried using the example from the manual, but still a new record gets inserted:
$userTable = Doctrine_Core::getTable('User');
$user = $userTable->find(2);
if ($user !== false) {
$user->username = 'Jack Daniels';
$user->save();
}
edit:
This example from the manual works:
$user = new User();
$user->assignIdentifier(1);
$user->username = 'jwage';
$user->save();
The funny thing is that I use this on another model and there it works OK. Maybe I have to fetch the whole array graph for this to work (I have another model in a one to many relationship)?
Do not, I repeat DO NOT use __construct() method in your models.
If you read the manual carefully you will see that you should use the construct() method (without “__” in front). Most of the things will work while using “__construct()” and calling parent::__construct() inside but the records state is not one them and this will cause all kinds of problems down the road, one of them is explained above 🙂
Guess we will have to wait for Doctrine 2.0 🙂