Skip to content

Commit a88f451

Browse files
committed
Simplifying code and make assotiation tests pass
1 parent c47e6b9 commit a88f451

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

Cake/ORM/Association/BelongsTo.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
namespace Cake\ORM\Association;
1818

19-
use Cake\Database\Expression\Comparison;
2019
use Cake\Database\Expression\FieldExpression;
2120
use Cake\ORM\Association;
2221
use Cake\ORM\Entity;
@@ -73,7 +72,7 @@ public function cascadeDelete(Entity $entity, $options = []) {
7372
* clause for getting the results on the target table.
7473
*
7574
* @param array $options list of options passed to attachTo method
76-
* @return boolean|QueryExpression
75+
* @return array
7776
*/
7877
protected function _joinCondition(array $options) {
7978
$field = sprintf(
@@ -86,7 +85,7 @@ protected function _joinCondition(array $options) {
8685
$this->_sourceTable->alias(),
8786
$options['foreignKey']
8887
));
89-
return new Comparison($field, $value, 'string', '=');
88+
return [$field => $value];
9089
}
9190

9291
}

Cake/ORM/Association/ExternalAssociationTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function _joinCondition(array $options) {
133133
$this->_targetTable->alias(),
134134
$options['foreignKey']
135135
));
136-
return new Comparison($field, $value, 'string', '=');
136+
return [$field => $value];
137137
}
138138

139139
/**

Cake/Test/TestCase/ORM/Association/BelongsToManyTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
namespace Cake\Test\TestCase\ORM\Association;
1818

19+
use Cake\Database\Expression\FieldExpression;
1920
use Cake\ORM\Association\BelongsToMany;
2021
use Cake\ORM\Entity;
2122
use Cake\ORM\Query;
@@ -183,11 +184,15 @@ public function testAttachTo() {
183184
'table' => 'tags'
184185
]
185186
]);
187+
188+
$field1 = new FieldExpression('ArticlesTag.article_id');
189+
$field2 = new FieldExpression('ArticlesTag.tag_id');
190+
186191
$query->expects($this->at(2))->method('join')->with([
187192
'ArticlesTag' => [
188193
'conditions' => [
189-
'Article.id = ArticlesTag.article_id',
190-
'Tag.id = ArticlesTag.tag_id'
194+
['Article.id' => $field1],
195+
['Tag.id' => $field2]
191196
],
192197
'type' => 'INNER',
193198
'table' => 'articles_tags'
@@ -233,11 +238,15 @@ public function testAttachToNoFields() {
233238
'table' => 'tags'
234239
]
235240
]);
241+
242+
$field1 = new FieldExpression('ArticlesTag.article_id');
243+
$field2 = new FieldExpression('ArticlesTag.tag_id');
244+
236245
$query->expects($this->at(1))->method('join')->with([
237246
'ArticlesTag' => [
238247
'conditions' => [
239-
'Article.id = ArticlesTag.article_id',
240-
'Tag.id = ArticlesTag.tag_id'
248+
['Article.id' => $field1],
249+
['Tag.id' => $field2]
241250
],
242251
'type' => 'INNER',
243252
'table' => 'articles_tags'

Cake/Test/TestCase/ORM/Association/BelongsToTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
namespace Cake\Test\TestCase\ORM\Association;
1818

19+
use Cake\Database\Expression\FieldExpression;
1920
use Cake\ORM\Association\BelongsTo;
2021
use Cake\ORM\Entity;
2122
use Cake\ORM\Query;
@@ -85,11 +86,12 @@ public function testAttachTo() {
8586
'conditions' => ['Company.is_active' => true]
8687
];
8788
$association = new BelongsTo('Company', $config);
89+
$field = new FieldExpression('Client.company_id');
8890
$query->expects($this->once())->method('join')->with([
8991
'Company' => [
9092
'conditions' => [
9193
'Company.is_active' => true,
92-
'Company.id = Client.company_id',
94+
['Company.id' => $field]
9395
],
9496
'table' => 'companies',
9597
'type' => 'LEFT'
@@ -149,11 +151,12 @@ public function testAttachToNoFields() {
149151
'conditions' => ['Company.is_active' => true]
150152
];
151153
$association = new BelongsTo('Company', $config);
154+
$field = new FieldExpression('Client.company_id');
152155
$query->expects($this->once())->method('join')->with([
153156
'Company' => [
154157
'conditions' => [
155158
'Company.is_active' => true,
156-
'Company.id = Client.company_id',
159+
['Company.id' => $field]
157160
],
158161
'type' => 'LEFT',
159162
'table' => 'companies',

Cake/Test/TestCase/ORM/Association/HasManyTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
namespace Cake\Test\TestCase\ORM\Association;
1818

19+
use Cake\Database\Expression\FieldExpression;
1920
use Cake\ORM\Association\HasMany;
2021
use Cake\ORM\Entity;
2122
use Cake\ORM\Query;
@@ -353,12 +354,14 @@ public function testAttachTo() {
353354
'targetTable' => $this->article,
354355
'conditions' => ['Article.is_active' => true]
355356
];
357+
358+
$field = new FieldExpression('Article.author_id');
356359
$association = new HasMany('Article', $config);
357360
$query->expects($this->once())->method('join')->with([
358361
'Article' => [
359362
'conditions' => [
360363
'Article.is_active' => true,
361-
'Author.id = Article.author_id',
364+
['Author.id' => $field]
362365
],
363366
'type' => 'INNER',
364367
'table' => 'articles'
@@ -423,7 +426,7 @@ public function testAttachToNoFields() {
423426
'Article' => [
424427
'conditions' => [
425428
'Article.is_active' => true,
426-
'Author.id = Article.author_id',
429+
['Author.id' => $field]
427430
],
428431
'type' => 'INNER',
429432
'table' => 'articles'

0 commit comments

Comments
 (0)