Skip to content

Commit 52e9d9b

Browse files
authored
Merge pull request #57 from alquerci/fix-reverse-relations-matching-while-hydrate-a-one-to-many-related
Fix reverse relations matching while hydrate a one to many related
2 parents 92671a5 + e1a7f48 commit 52e9d9b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/Doctrine/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ public function add($record, $key = null)
471471
}
472472
$relations = $this->relation['table']->getRelations();
473473
foreach ($relations as $relation) {
474-
if ($this->relation['class'] == $relation['localTable']->getOption('name') && $relation->getLocal() == $this->relation->getForeignFieldName()) {
474+
if ($this->relation['localTable']->getOption('name') == $relation['class'] && $relation->getLocal() == $this->relation->getForeignFieldName()) {
475475
$record->{$relation['alias']} = $this->reference;
476476
break;
477477
}

tests/Hydrate/CollectionInitializationTestCase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,23 @@ public function testCollectionsAreReinitializedOnHydration()
8888
$this->assertEqual('112', $users[0]->Phonenumber[0]->phonenumber);
8989
$this->assertEqual('110', $users[0]->Phonenumber[1]->phonenumber);
9090
}
91+
92+
public function testOneToManyReverseMatching()
93+
{
94+
$users = Doctrine_Query::create()
95+
->from('User u')
96+
->leftJoin('u.Phonenumber p')
97+
->having('COUNT(p.id) > 0')
98+
->groupBy('u.id')
99+
->limit(1)
100+
->execute()
101+
;
102+
103+
$expectedUser = $users->getFirst();
104+
105+
// Explicitly not load the record as the reverse matching do it for us.
106+
$actualUser = $expectedUser->Phonenumber->getFirst()->get('User', false);
107+
108+
$this->assertIdentical($expectedUser, $actualUser);
109+
}
91110
}

tests/Ticket/1674TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testTest()
4444

4545
$xml = $users->exportTo('xml');
4646
$this->assertEqual($xml, '<?xml version="1.0" encoding="utf-8"?>
47-
<data><User id="4" type="0" email_id="1"><name>zYne</name><loginname/><password/><created/><updated/><Phonenumber><Phonenumber id="2" entity_id="4"><phonenumber>123 123</phonenumber><Entity/></Phonenumber></Phonenumber></User></data>
47+
<data><User id="4" type="0" email_id="1"><name>zYne</name><loginname/><password/><created/><updated/><Phonenumber><Phonenumber id="2" entity_id="4"><phonenumber>123 123</phonenumber><User/></Phonenumber></Phonenumber></User></data>
4848
');
4949
}
5050
}

0 commit comments

Comments
 (0)