Commit 7ca53970 authored by zYne's avatar zYne

Session flushing bug with proxy objects fixed

parent bdce1d8d
...@@ -422,7 +422,35 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -422,7 +422,35 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key] = $record; $this->data[$key] = $record;
} }
/**
* adds a record to collection
* @param Doctrine_Record $record record to be added
* @param string $key optional key for the record
* @return boolean
*/
public function internalAdd(Doctrine_Record $record,$key = null) {
if(in_array($record,$this->data))
return false;
if(isset($this->reference_field))
$record->internalSet($this->reference_field,$this->reference);
if(isset($key)) {
if(isset($this->data[$key]))
return false;
$this->data[$key] = $record;
return true;
}
if(isset($this->generator)) {
$key = $this->generator->getIndex($record);
$this->data[$key] = $record;
} else
$this->data[] = $record;
return true;
}
/** /**
* adds a record to collection * adds a record to collection
* @param Doctrine_Record $record record to be added * @param Doctrine_Record $record record to be added
......
...@@ -626,9 +626,10 @@ class Doctrine_Query extends Doctrine_Hydrate { ...@@ -626,9 +626,10 @@ class Doctrine_Query extends Doctrine_Hydrate {
if($fk->getType() == Doctrine_Relation::MANY_AGGREGATE || if($fk->getType() == Doctrine_Relation::MANY_AGGREGATE ||
$fk->getType() == Doctrine_Relation::MANY_COMPOSITE) { $fk->getType() == Doctrine_Relation::MANY_COMPOSITE) {
if( ! $loadFields) if( ! $loadFields) {
$this->subqueryAliases[] = $tname2; $this->subqueryAliases[] = $tname2;
}
$this->needsSubquery = true; $this->needsSubquery = true;
} }
......
...@@ -1035,8 +1035,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1035,8 +1035,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function addReference(Doctrine_Record $record, Doctrine_Relation $connector, $key = null) { public function addReference(Doctrine_Record $record, Doctrine_Relation $connector, $key = null) {
$alias = $connector->getAlias(); $alias = $connector->getAlias();
$this->references[$alias]->add($record, $key); $this->references[$alias]->internalAdd($record, $key);
$this->originals[$alias]->add($record, $key); $this->originals[$alias]->internalAdd($record, $key);
} }
/** /**
* getReferences * getReferences
......
...@@ -29,6 +29,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -29,6 +29,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(), 5); $this->assertEqual($users->count(), 5);
$users[0]->Phonenumber[0]; $users[0]->Phonenumber[0];
$this->assertEqual($count, $this->dbh->count()); $this->assertEqual($count, $this->dbh->count());
$this->assertEqual($this->query->getQuery(), $this->assertEqual($this->query->getQuery(),
'SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity WHERE (entity.type = 0) LIMIT 5) AND (entity.type = 0)'); 'SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity WHERE (entity.type = 0) LIMIT 5) AND (entity.type = 0)');
...@@ -41,6 +43,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -41,6 +43,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$users[3]->Phonenumber[0]; $users[3]->Phonenumber[0];
$this->assertEqual($count, $this->dbh->count()); $this->assertEqual($count, $this->dbh->count());
} }
public function testLimitWithOneToManyLeftJoinAndCondition() { public function testLimitWithOneToManyLeftJoinAndCondition() {
$q = new Doctrine_Query($this->session); $q = new Doctrine_Query($this->session);
$q->from("User(name)")->where("User.Phonenumber.phonenumber LIKE '%123%'")->limit(5); $q->from("User(name)")->where("User.Phonenumber.phonenumber LIKE '%123%'")->limit(5);
...@@ -53,10 +56,11 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -53,10 +56,11 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users[4]->name, 'Jean Reno'); $this->assertEqual($users[4]->name, 'Jean Reno');
$this->assertEqual($users->count(), 5); $this->assertEqual($users->count(), 5);
$this->assertEqual($q->getQuery(), $this->assertEqual($q->getQuery(),
"SELECT entity.id AS entity__id, entity.name AS entity__name FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE phonenumber.phonenumber LIKE '%123%' AND (entity.type = 0) LIMIT 5) AND phonenumber.phonenumber LIKE '%123%' AND (entity.type = 0)"); "SELECT entity.id AS entity__id, entity.name AS entity__name FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE phonenumber.phonenumber LIKE '%123%' AND (entity.type = 0) LIMIT 5) AND phonenumber.phonenumber LIKE '%123%' AND (entity.type = 0)");
} }
public function testLimitWithOneToManyLeftJoinAndOrderBy() { public function testLimitWithOneToManyLeftJoinAndOrderBy() {
$q = new Doctrine_Query($this->session); $q = new Doctrine_Query($this->session);
$q->from("User(name)")->where("User.Phonenumber.phonenumber LIKE '%123%'")->orderby("User.Email.address")->limit(5); $q->from("User(name)")->where("User.Phonenumber.phonenumber LIKE '%123%'")->orderby("User.Email.address")->limit(5);
...@@ -108,7 +112,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -108,7 +112,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$count = $this->dbh->count(); $count = $this->dbh->count();
$users[0]->Phonenumber[0]; $users[0]->Phonenumber[0];
$this->assertEqual($count, $this->dbh->count()); $this->assertEqual($count, $this->dbh->count());
$this->assertEqual($q->getQuery(), $this->assertEqual($q->getQuery(),
'SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity WHERE entity.name = ? AND (entity.type = 0) LIMIT 5) AND entity.name = ? AND (entity.type = 0)'); 'SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity WHERE entity.name = ? AND (entity.type = 0) LIMIT 5) AND entity.name = ? AND (entity.type = 0)');
...@@ -116,23 +120,70 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -116,23 +120,70 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$q->from("User(id).Phonenumber(id)"); $q->from("User(id).Phonenumber(id)");
$q->where("User.name LIKE ? || User.name LIKE ?"); $q->where("User.name LIKE ? || User.name LIKE ?");
$q->limit(5); $q->limit(5);
$users = $q->execute(array('%zYne%', '%Arnold%')); $users = $q->execute(array('%zYne%', '%Arnold%'));
$this->assertEqual($users->count(), 2); $this->assertEqual($users->count(), 2);
$count = $this->dbh->count(); $count = $this->dbh->count();
$users[0]->Phonenumber[0]; $users[0]->Phonenumber[0];
$this->assertEqual($count, $this->dbh->count()); $this->assertEqual($count, $this->dbh->count());
$this->assertEqual($q->getQuery(), $this->assertEqual($q->getQuery(),
"SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity WHERE (entity.name LIKE ? OR entity.name LIKE ?) AND (entity.type = 0) LIMIT 5) AND (entity.name LIKE ? OR entity.name LIKE ?) AND (entity.type = 0)"); "SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity WHERE (entity.name LIKE ? OR entity.name LIKE ?) AND (entity.type = 0) LIMIT 5) AND (entity.name LIKE ? OR entity.name LIKE ?) AND (entity.type = 0)");
}
public function testConnectionFlushing() {
$q = new Doctrine_Query();
$q->from("User(id).Phonenumber(id)");
$q->where("User.name = ?");
$q->limit(5);
$users = $q->execute(array('zYne'));
$this->assertEqual($users->count(), 1);
$this->session->flush();
} }
public function testLimitWithManyToManyLeftJoin() { public function testLimitWithManyToManyLeftJoin() {
$q = new Doctrine_Query($this->session); $q = new Doctrine_Query($this->session);
$q->from("User.Group")->limit(5); $q->from("User.Group")->limit(5);
$users = $q->execute(); $users = $q->execute();
$this->assertEqual($users->count(), 5); $this->assertEqual($users->count(), 5);
$user = $this->objTable->find(5);
$user->Group[1]->name = "Tough guys inc.";
$user->Group[2]->name = "Terminators";
$user2 = $this->objTable->find(4);
$user2->Group = $user->Group;
$user3 = $this->objTable->find(6);
$user3->Group = $user->Group;
$this->assertEqual($user->Group[0]->name, "Action Actors");
$this->session->flush();
$this->assertEqual($user->Group[0]->name, "Action Actors");
$this->assertEqual(count($user->Group), 3);
$q = new Doctrine_Query();
$q->from("User")->where("User.Group.id = ?")->orderby("User.id DESC")->limit(5);
$users = $q->execute(array($user->Group[1]->id));
$this->assertEqual($users->count(), 3);
$this->session->clear();
$q = new Doctrine_Query();
$q->from("User")->where("User.Group.id = ?")->orderby("User.id DESC");
$users = $q->execute(array($user->Group[1]->id));
$this->assertEqual($users->count(), 3);
} }
} }
?> ?>
...@@ -63,11 +63,12 @@ $test->addTestCase(new Doctrine_ValidatorTestCase()); ...@@ -63,11 +63,12 @@ $test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase()); $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_QueryTestCase()); $test->addTestCase(new Doctrine_QueryTestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase()); $test->addTestCase(new Doctrine_Query_Limit_TestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment