Skip to content

Commit

Permalink
Adding a quite important missing part to join generation in BelonsTo and
Browse files Browse the repository at this point in the history
HasOne
  • Loading branch information
lorenzo committed May 12, 2013
1 parent 22c3ced commit be991c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/Cake/ORM/Association/BelongsTo.php
Expand Up @@ -74,7 +74,8 @@ public function attachTo(Query $query, array $options = []) {
'includeFields' => true,
'foreignKey' => $this->foreignKey(),
'conditions' => [],
'type' => $this->joinType()
'type' => $this->joinType(),
'table' => $target->table()
];
$options['conditions'] = array_merge($this->conditions(), $options['conditions']);

Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/ORM/Association/HasOne.php
Expand Up @@ -82,7 +82,8 @@ public function attachTo(Query $query, array $options = []) {
'includeFields' => true,
'foreignKey' => $this->foreignKey(),
'conditions' => [],
'type' => $this->joinType()
'type' => $this->joinType(),
'table' => $target->table()
];
$options['conditions'] = array_merge($this->conditions(), $options['conditions']);

Expand Down
7 changes: 5 additions & 2 deletions lib/Cake/Test/TestCase/ORM/Association/BelongsToTest.php
Expand Up @@ -87,6 +87,7 @@ public function testAttachTo() {
'Company.is_active' => true,
'Company.id = Client.company_id',
],
'table' => 'companies',
'type' => 'LEFT'
]
]);
Expand Down Expand Up @@ -115,7 +116,8 @@ public function testAttachToConfigOverride() {
'conditions' => [
'Company.is_active' => false
],
'type' => 'LEFT'
'type' => 'LEFT',
'table' => 'companies',
]
]);
$query->expects($this->once())->method('select')->with([
Expand Down Expand Up @@ -149,7 +151,8 @@ public function testAttachToNoFields() {
'Company.is_active' => true,
'Company.id = Client.company_id',
],
'type' => 'LEFT'
'type' => 'LEFT',
'table' => 'companies',
]
]);
$query->expects($this->never())->method('select');
Expand Down
9 changes: 6 additions & 3 deletions lib/Cake/Test/TestCase/ORM/Association/HasOneTest.php
Expand Up @@ -87,7 +87,8 @@ public function testAttachTo() {
'Profile.is_active' => true,
'User.id = Profile.user_id',
],
'type' => 'INNER'
'type' => 'INNER',
'table' => 'profiles'
]
]);
$query->expects($this->once())->method('select')->with([
Expand Down Expand Up @@ -117,7 +118,8 @@ public function testAttachToConfigOverride() {
'conditions' => [
'Profile.is_active' => false
],
'type' => 'INNER'
'type' => 'INNER',
'table' => 'profiles'
]
]);
$query->expects($this->once())->method('select')->with([
Expand Down Expand Up @@ -151,7 +153,8 @@ public function testAttachToNoFields() {
'Profile.is_active' => true,
'User.id = Profile.user_id',
],
'type' => 'INNER'
'type' => 'INNER',
'table' => 'profiles'
]
]);
$query->expects($this->never())->method('select');
Expand Down

0 comments on commit be991c6

Please sign in to comment.