Browse Source

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
mark_story 11 years ago
parent
commit
fbed75aa33

+ 0 - 7
src/ORM/Association/HasOne.php

@@ -33,13 +33,6 @@ class HasOne extends Association {
 	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
  *

+ 5 - 5
tests/TestCase/ORM/Association/HasOneTest.php

@@ -107,7 +107,7 @@ class HasOneTest extends \Cake\TestSuite\TestCase {
 					'Profiles.is_active' => true,
 					['Users.id' => $field],
 				], $this->profilesTypeMap),
-				'type' => 'INNER',
+				'type' => 'LEFT',
 				'table' => 'profiles'
 			]
 		]);
@@ -138,7 +138,7 @@ class HasOneTest extends \Cake\TestSuite\TestCase {
 				'conditions' => new QueryExpression([
 					'Profiles.is_active' => false
 				], $this->profilesTypeMap),
-				'type' => 'INNER',
+				'type' => 'LEFT',
 				'table' => 'profiles'
 			]
 		]);
@@ -174,7 +174,7 @@ class HasOneTest extends \Cake\TestSuite\TestCase {
 					'Profiles.is_active' => true,
 					['Users.id' => $field],
 				], $this->profilesTypeMap),
-				'type' => 'INNER',
+				'type' => 'LEFT',
 				'table' => 'profiles'
 			]
 		]);
@@ -204,7 +204,7 @@ class HasOneTest extends \Cake\TestSuite\TestCase {
 					'Profiles.is_active' => true,
 					['Users.id' => $field],
 				], $this->profilesTypeMap),
-				'type' => 'INNER',
+				'type' => 'LEFT',
 				'table' => 'profiles'
 			]
 		]);
@@ -243,7 +243,7 @@ class HasOneTest extends \Cake\TestSuite\TestCase {
 					'Profiles.is_active' => true,
 					['Users.id' => $field1, 'Users.site_id' => $field2],
 				], $this->profilesTypeMap),
-				'type' => 'INNER',
+				'type' => 'LEFT',
 				'table' => 'profiles'
 			]
 		]);

+ 2 - 2
tests/TestCase/ORM/EagerLoaderTest.php

@@ -162,7 +162,7 @@ class EagerLoaderTest extends TestCase {
 		$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 @@ class EagerLoaderTest extends TestCase {
 		$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)

+ 0 - 1
tests/TestCase/ORM/QueryRegressionTest.php

@@ -126,7 +126,6 @@ class QueryRegressionTest extends TestCase {
 		$this->assertNull($entity->created);
 	}
 
-
 /**
  * Test for https://github.com/cakephp/cakephp/issues/3626
  *