fixes #310
This commit is contained in:
parent
b81f399c12
commit
7a9a86a5c6
@ -42,6 +42,10 @@ class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->stmt = $stmt;
|
||||
|
||||
if ($stmt === false) {
|
||||
throw new Doctrine_Db_Exception('Unknown statement object given.');
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
@ -382,7 +382,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private function cleanData($debug = false)
|
||||
private function cleanData()
|
||||
{
|
||||
$tmp = $this->_data;
|
||||
|
||||
@ -397,42 +397,57 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$this->_data[$name] = self::$null;
|
||||
} else {
|
||||
switch ($type) {
|
||||
case "array":
|
||||
case "object":
|
||||
case 'array':
|
||||
case 'object':
|
||||
if ($tmp[$name] !== self::$null) {
|
||||
if (is_string($tmp[$name])) {
|
||||
$value = unserialize($tmp[$name]);
|
||||
|
||||
if ($value === false)
|
||||
throw new Doctrine_Record_Exception("Unserialization of $name failed.");
|
||||
throw new Doctrine_Record_Exception('Unserialization of ' . $name . ' failed.');
|
||||
} else {
|
||||
$value = $tmp[$name];
|
||||
}
|
||||
$this->_data[$name] = $value;
|
||||
}
|
||||
break;
|
||||
case "gzip":
|
||||
case 'gzip':
|
||||
if ($tmp[$name] !== self::$null) {
|
||||
$value = gzuncompress($tmp[$name]);
|
||||
|
||||
if ($value === false)
|
||||
throw new Doctrine_Record_Exception("Uncompressing of $name failed.");
|
||||
throw new Doctrine_Record_Exception('Uncompressing of ' . $name . ' failed.');
|
||||
|
||||
$this->_data[$name] = $value;
|
||||
}
|
||||
break;
|
||||
case "enum":
|
||||
case 'enum':
|
||||
$this->_data[$name] = $this->_table->enumValue($name, $tmp[$name]);
|
||||
break;
|
||||
default:
|
||||
$this->_data[$name] = $tmp[$name];
|
||||
};
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
/**
|
||||
* hydrate
|
||||
* hydrates this object from given array
|
||||
*
|
||||
* @param array $data
|
||||
* @return boolean
|
||||
*/
|
||||
public function hydrate(array $data)
|
||||
{
|
||||
foreach ($data as $k => $v) {
|
||||
$this->_data[$k] = $v;
|
||||
}
|
||||
$this->cleanData();
|
||||
$this->prepareIdentifiers();
|
||||
}
|
||||
/**
|
||||
* prepareIdentifiers
|
||||
* prepares identifiers for later use
|
||||
|
@ -1144,6 +1144,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
|
||||
if (isset($this->identityMap[$id])) {
|
||||
$record = $this->identityMap[$id];
|
||||
$record->hydrate($this->data);
|
||||
} else {
|
||||
$recordName = $this->getClassnameToReturn();
|
||||
$record = new $recordName($this);
|
||||
@ -1183,7 +1184,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$nomatch) {
|
||||
if ( ! $nomatch) {
|
||||
return $table->getComponentName();
|
||||
}
|
||||
}
|
||||
|
@ -107,4 +107,27 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY);
|
||||
}
|
||||
public function testProxiesAreAutomaticallyUpdatedWithFetches()
|
||||
{
|
||||
$user = new User();
|
||||
$user->name = 'someuser';
|
||||
$user->password = '123';
|
||||
$user->save();
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$user = $this->connection->queryOne("SELECT u.name FROM User u WHERE u.name = 'someuser'");
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY);
|
||||
|
||||
$user2 = $this->connection->queryOne("FROM User u WHERE u.name = 'someuser'");
|
||||
|
||||
$this->assertEqual($user->getOID(), $user2->getOID());
|
||||
|
||||
$count = count($this->dbh);
|
||||
|
||||
$this->assertEqual($user->password, '123');
|
||||
|
||||
$this->assertEqual($count, count($this->dbh));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user