renamed Doctrine_Record::obtainIdentifier() to Doctrine_Record::identifier(), fixed identityMap implementation
This commit is contained in:
parent
3874be57a4
commit
58f6d356e0
@ -403,7 +403,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
}
|
||||
|
||||
$params = array_values($array);
|
||||
$id = $record->obtainIdentifier();
|
||||
$id = $record->identifier();
|
||||
|
||||
if ( ! is_array($id)) {
|
||||
$id = array($id);
|
||||
@ -477,6 +477,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
$record->assignIdentifier(true);
|
||||
}
|
||||
}
|
||||
$record->getTable()->addRecord($record);
|
||||
|
||||
$record->postInsert($event);
|
||||
|
||||
return true;
|
||||
|
@ -612,7 +612,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
$id = $this->obtainIdentifier();
|
||||
$id = $this->identifier();
|
||||
if ( ! is_array($id)) {
|
||||
$id = array($id);
|
||||
}
|
||||
@ -631,8 +631,6 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist.');
|
||||
}
|
||||
|
||||
$this->_data = array_change_key_case($this->_data, CASE_LOWER);
|
||||
|
||||
$this->_modified = array();
|
||||
$this->_data = $this->_filter->cleanData($this->_data);
|
||||
|
||||
@ -1226,7 +1224,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function obtainIdentifier()
|
||||
public function identifier()
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
|
@ -881,6 +881,25 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
{
|
||||
$this->identityMap = array();
|
||||
}
|
||||
/**
|
||||
* addRecord
|
||||
* adds a record to identity map
|
||||
*
|
||||
* @param Doctrine_Record $record record to be added
|
||||
* @return boolean
|
||||
*/
|
||||
public function addRecord(Doctrine_Record $record)
|
||||
{
|
||||
$id = implode(' ', $record->identifier());
|
||||
|
||||
if (isset($this->identityMap[$id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->identityMap[$id] = $record;
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* getRecord
|
||||
* first checks if record exists in identityMap, if not
|
||||
@ -1207,7 +1226,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
break;
|
||||
case 'integer':
|
||||
return (int) $value;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
|
@ -205,7 +205,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
|
||||
$params = array();
|
||||
$cond = array();
|
||||
foreach ($deletes as $k => $record) {
|
||||
$ids = $record->obtainIdentifier();
|
||||
$ids = $record->identifier();
|
||||
$tmp = array();
|
||||
foreach (array_keys($ids) as $id){
|
||||
$tmp[] = $id . ' = ? ';
|
||||
|
@ -30,16 +30,23 @@
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareData() { }
|
||||
public function prepareTables() {
|
||||
class Doctrine_Access_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function prepareData()
|
||||
{ }
|
||||
|
||||
public function prepareTables()
|
||||
{
|
||||
$this->tables = array('Entity', 'User');
|
||||
parent::prepareTables();
|
||||
}
|
||||
public function testUnset() {
|
||||
|
||||
public function testUnset()
|
||||
{
|
||||
|
||||
}
|
||||
public function testIsset() {
|
||||
public function testIsset()
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$this->assertTrue(isset($user->name));
|
||||
@ -59,7 +66,9 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
|
||||
// test repeated call
|
||||
$this->assertTrue(isset($coll[0]));
|
||||
}
|
||||
public function testOffsetMethods() {
|
||||
|
||||
public function testOffsetMethods()
|
||||
{
|
||||
$user = new User();
|
||||
$this->assertEqual($user['name'],null);
|
||||
|
||||
@ -68,7 +77,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$user->save();
|
||||
|
||||
$user = $this->connection->getTable('User')->find($user->obtainIdentifier());
|
||||
$user = $this->connection->getTable('User')->find($user->identifier());
|
||||
$this->assertEqual($user->name, 'Jack');
|
||||
|
||||
$user['name'] = 'Jack';
|
||||
@ -76,7 +85,9 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
|
||||
$user['name'] = 'zYne';
|
||||
$this->assertEqual($user['name'], 'zYne');
|
||||
}
|
||||
public function testOverload() {
|
||||
|
||||
public function testOverload()
|
||||
{
|
||||
$user = new User();
|
||||
$this->assertEqual($user->name,null);
|
||||
|
||||
@ -86,7 +97,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$user->save();
|
||||
|
||||
$user = $this->connection->getTable('User')->find($user->obtainIdentifier());
|
||||
$user = $this->connection->getTable('User')->find($user->identifier());
|
||||
$this->assertEqual($user->name, 'Jack');
|
||||
|
||||
$user->name = 'Jack';
|
||||
@ -94,6 +105,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
|
||||
$user->name = 'zYne';
|
||||
$this->assertEqual($user->name, 'zYne');
|
||||
}
|
||||
|
||||
public function testSet() {
|
||||
$user = new User();
|
||||
$this->assertEqual($user->get('name'),null);
|
||||
@ -103,7 +115,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$user->save();
|
||||
|
||||
$user = $this->connection->getTable('User')->find($user->obtainIdentifier());
|
||||
$user = $this->connection->getTable('User')->find($user->identifier());
|
||||
|
||||
$this->assertEqual($user->get('name'), 'Jack');
|
||||
|
||||
|
@ -30,28 +30,32 @@
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_CustomPrimaryKey_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareData() { }
|
||||
class Doctrine_CustomPrimaryKey_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function prepareData()
|
||||
{ }
|
||||
|
||||
public function prepareTables() {
|
||||
public function prepareTables()
|
||||
{
|
||||
$this->tables = array('CustomPK');
|
||||
|
||||
parent::prepareTables();
|
||||
}
|
||||
public function testOperations() {
|
||||
public function testOperations()
|
||||
{
|
||||
$c = new CustomPK();
|
||||
$this->assertTrue($c instanceof Doctrine_Record);
|
||||
|
||||
$c->name = 'custom pk test';
|
||||
$this->assertEqual($c->obtainIdentifier(), array());
|
||||
$this->assertEqual($c->identifier(), array());
|
||||
|
||||
$c->save();
|
||||
$this->assertEqual($c->obtainIdentifier(), array('uid' => 1));
|
||||
$this->assertEqual($c->identifier(), array('uid' => 1));
|
||||
$this->connection->clear();
|
||||
|
||||
$c = $this->connection->getTable('CustomPK')->find(1);
|
||||
|
||||
$this->assertEqual($c->obtainIdentifier(), array('uid' => 1));
|
||||
$this->assertEqual($c->identifier(), array('uid' => 1));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -62,6 +62,7 @@ class Doctrine_Expression_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->assertEqual($e->getSql(), '1 + 2');
|
||||
}
|
||||
|
||||
public function testExpressionParserSupportsFunctionComposition()
|
||||
{
|
||||
$e = new Doctrine_Expression("SUBSTRING(CONCAT('some', 'one'), 0, 3)");
|
||||
|
@ -187,7 +187,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$user2 = unserialize($str);
|
||||
|
||||
$this->assertTrue($user2 instanceof User);
|
||||
$this->assertEqual($user2->obtainIdentifier(), $user->obtainIdentifier());
|
||||
$this->assertEqual($user2->identifier(), $user->identifier());
|
||||
}
|
||||
|
||||
public function testCallback()
|
||||
@ -204,7 +204,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$record = new EntityReference();
|
||||
$this->assertEqual($record->getTable()->getIdentifier(), array("entity1","entity2"));
|
||||
$this->assertEqual($record->getTable()->getIdentifierType(), Doctrine::IDENTIFIER_COMPOSITE);
|
||||
$this->assertEqual($record->obtainIdentifier(), array("entity1" => null, "entity2" => null));
|
||||
$this->assertEqual($record->identifier(), array("entity1" => null, "entity2" => null));
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_TCLEAN);
|
||||
|
||||
$record->entity1 = 3;
|
||||
@ -212,45 +212,45 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($record->entity2, 4);
|
||||
$this->assertEqual($record->entity1, 3);
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_TDIRTY);
|
||||
$this->assertEqual($record->obtainIdentifier(), array("entity1" => null, "entity2" => null));
|
||||
$this->assertEqual($record->identifier(), array("entity1" => null, "entity2" => null));
|
||||
|
||||
$record->save();
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 4);
|
||||
$this->assertEqual($record->entity1, 3);
|
||||
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 3, "entity2" => 4));
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
|
||||
|
||||
$record = $record->getTable()->find($record->obtainIdentifier());
|
||||
$record = $record->getTable()->find($record->identifier());
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 4);
|
||||
$this->assertEqual($record->entity1, 3);
|
||||
|
||||
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 3, "entity2" => 4));
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
|
||||
|
||||
$record->entity2 = 5;
|
||||
$record->entity1 = 2;
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_DIRTY);
|
||||
$this->assertEqual($record->entity2, 5);
|
||||
$this->assertEqual($record->entity1, 2);
|
||||
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 3, "entity2" => 4));
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
|
||||
|
||||
$record->save();
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 5);
|
||||
$this->assertEqual($record->entity1, 2);
|
||||
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 2, "entity2" => 5));
|
||||
$record = $record->getTable()->find($record->obtainIdentifier());
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
|
||||
$record = $record->getTable()->find($record->identifier());
|
||||
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 5);
|
||||
$this->assertEqual($record->entity1, 2);
|
||||
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 2, "entity2" => 5));
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
|
||||
|
||||
$record->refresh();
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 5);
|
||||
$this->assertEqual($record->entity1, 2);
|
||||
$this->assertEqual($record->obtainIdentifier(), array("entity1" => 2, "entity2" => 5));
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
|
||||
|
||||
$record = new EntityReference();
|
||||
$record->entity2 = 6;
|
||||
@ -301,7 +301,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->connection->flush();
|
||||
|
||||
$task = $task->getTable()->find($task->obtainIdentifier());
|
||||
$task = $task->getTable()->find($task->identifier());
|
||||
|
||||
$this->assertEqual($task->name, "Task 1");
|
||||
$this->assertEqual($task->ResourceAlias[0]->name, "Resource 1");
|
||||
@ -373,7 +373,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($user->created, null);
|
||||
$this->assertEqual($user->updated, null);
|
||||
$user->save();
|
||||
$id = $user->obtainIdentifier();
|
||||
$id = $user->identifier();
|
||||
$user = $user->getTable()->find($id);
|
||||
$this->assertEqual($user->name, "Jack Daniels");
|
||||
$this->assertEqual($user->created, null);
|
||||
@ -439,7 +439,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($c->name, "child 1");
|
||||
|
||||
$this->assertEqual($e->Child[0]->parent_id, 1);
|
||||
$this->assertEqual($e->Child[0]->Parent->obtainIdentifier(), $e->obtainIdentifier());
|
||||
$this->assertEqual($e->Child[0]->Parent->identifier(), $e->identifier());
|
||||
|
||||
|
||||
$this->assertEqual($e->Child[1]->parent_id, 1);
|
||||
@ -786,8 +786,8 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$user->save();
|
||||
|
||||
$this->assertEqual($user->Group->count(), 2);
|
||||
$this->assertEqual($user->Group[1]->obtainIdentifier(), $record2->obtainIdentifier());
|
||||
$this->assertFalse($user->Group[1]->obtainIdentifier() == $record->obtainIdentifier());
|
||||
$this->assertEqual($user->Group[1]->identifier(), $record2->identifier());
|
||||
$this->assertFalse($user->Group[1]->identifier() == $record->identifier());
|
||||
|
||||
|
||||
$user->Group[0] = $record;
|
||||
|
Loading…
Reference in New Issue
Block a user