Skip to content
Permalink
Browse files

Make hasOne associations default to LEFT joins.

Using an INNER join makes the hasOne association data required. However,
there are many valid cases where a hasOne association might not have
data. We should stil load the parent record in these cases.

Refs #3902
  • Loading branch information...
markstory committed Jul 8, 2014
1 parent 2ae1fd9 commit fbed75aa3370751180c04dbe511b324add95d292
@@ -32,13 +32,6 @@ class HasOne extends Association {
use DependentDeleteTrait;
use SelectableAssociationTrait;
/**
* The type of join to be used when adding the association to a query
*
* @var string
*/
protected $_joinType = 'INNER';
/**
* Sets the name of the field representing the foreign key to the target table.
* If no parameters are passed current field is returned
@@ -107,7 +107,7 @@ public function testAttachTo() {
'Profiles.is_active' => true,
['Users.id' => $field],
], $this->profilesTypeMap),
'type' => 'INNER',
'type' => 'LEFT',
'table' => 'profiles'
]
]);
@@ -138,7 +138,7 @@ public function testAttachToConfigOverride() {
'conditions' => new QueryExpression([
'Profiles.is_active' => false
], $this->profilesTypeMap),
'type' => 'INNER',
'type' => 'LEFT',
'table' => 'profiles'
]
]);
@@ -174,7 +174,7 @@ public function testAttachToNoFields() {
'Profiles.is_active' => true,
['Users.id' => $field],
], $this->profilesTypeMap),
'type' => 'INNER',
'type' => 'LEFT',
'table' => 'profiles'
]
]);
@@ -204,7 +204,7 @@ public function testAttachToWithQueryBuilder() {
'Profiles.is_active' => true,
['Users.id' => $field],
], $this->profilesTypeMap),
'type' => 'INNER',
'type' => 'LEFT',
'table' => 'profiles'
]
]);
@@ -243,7 +243,7 @@ public function testAttachToMultiPrimaryKey() {
'Profiles.is_active' => true,
['Users.id' => $field1, 'Users.site_id' => $field2],
], $this->profilesTypeMap),
'type' => 'INNER',
'type' => 'LEFT',
'table' => 'profiles'
]
]);
@@ -162,7 +162,7 @@ public function testContainToJoinsOneLevel() {
$query->expects($this->at(1))->method('join')
->with(['orders' => [
'table' => 'orders',
'type' => 'INNER',
'type' => 'LEFT',
'conditions' => new QueryExpression([
['clients.id' => new IdentifierExpression('orders.client_id')]
], $this->ordersTypeMap)
@@ -182,7 +182,7 @@ public function testContainToJoinsOneLevel() {
$query->expects($this->at(3))->method('join')
->with(['stuff' => [
'table' => 'things',
'type' => 'INNER',
'type' => 'LEFT',
'conditions' => new QueryExpression([
['orders.id' => new IdentifierExpression('stuff.order_id')]
], $this->stuffTypeMap)
@@ -126,7 +126,6 @@ public function testNullableTimeColumn() {
$this->assertNull($entity->created);
}
/**
* Test for https://github.com/cakephp/cakephp/issues/3626
*

0 comments on commit fbed75a

Please sign in to comment.
You can’t perform that action at this time.