Doctrine inserts when it should update
Posted
by Goran Juric
on Stack Overflow
See other posts from Stack Overflow
or by Goran Juric
Published on 2010-06-16T14:41:29Z
Indexed on
2010/06/16
16:32 UTC
Read the original article
Hit count: 258
doctrine
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)?
© Stack Overflow or respective owner