Details
Description
Assigning a new unsaved relation to an entity confuses getModified() to return records for values such as userId, that are expected to be ints.
Here is a full example to reproduce:
<?php
require_once '_loader.php';
$mgr = Doctrine_Manager::getInstance();
$mgr->openConnection('....');
class User extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('t_users');
$this->hasColumn('name', 'string', 32);
}
}
class Post extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('t_posts');
$this->hasColumn('body', 'string', 256);
$this->hasColumn('userId', 'integer');
}
public function setUp()
{
$this->hasOne('User', array(
'local' => 'userId',
'foreign' => 'id'
));
}
}
Doctrine::dropDatabases();
Doctrine::createDatabases();
Doctrine::createTablesFromArray(array('User', 'Post'));
$joe = new User();
$joe->name = 'Joe';
$joe->save();
$post = new Post();
$post->body = 'Hi';
$post->User = $joe;
$post->save();
$bill = new User();
$bill->name = 'Bill';
//$bill->save(); // If this is uncommented everything works fine
$post->User = $bill;
var_dump(' --- New --- ');
var_dump($post->getModified());
And instead of a id for userId I get this
string(13) " --- New --- " array(1) { ["userId"]=> object(User)#37 (18) { ["_node:protected"]=> NULL ["_id:protected"]=> array(0) { } ["_data:protected"]=> array(2) { ["id"]=> object(Doctrine_Null)#4 (0) { } ["name"]=> string(4) "Bill" } ["_values:protected"]=> array(0) { } ["_state:protected"]=> int(2) ["_lastModified:protected"]=> array(0) { } ["_modified:protected"]=> array(1) { [0]=> string(4) "name" } ["_oldValues:protected"]=> array(1) { ["name"]=> NULL } ... trimmed ...
expected
string(13) " --- New --- " array(1) { ["userId"]=> string(1) "2" }
Tested on 1.1 and 1.2 branches from svn. (same result)
This is the expected behavior. Because you haven't saved $bill yet, it is temporarily storing the reference to the object in the foreign key field.