Skip to content
Permalink
Browse files

Use interface const instead of magic strings for LEFT/RIGHT/INNER joi…

…n types.
  • Loading branch information...
dereuromark committed Sep 25, 2017
1 parent 8dea5d8 commit d5ae64197b90cd334a2efa7d7e9f789d6fa628b8
@@ -19,6 +19,7 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\Expression\ValuesExpression;
use Cake\Database\Statement\CallbackStatement;
use Cake\Datasource\QueryInterface;
use InvalidArgumentException;
use IteratorAggregate;
use RuntimeException;
@@ -613,7 +614,7 @@ public function join($tables = null, $types = [], $overwrite = false)
$t['conditions'] = $this->newExpr()->add($t['conditions'], $types);
}
$alias = is_string($alias) ? $alias : null;
$joins[$alias ?: $i++] = $t + ['type' => 'INNER', 'alias' => $alias];
$joins[$alias ?: $i++] = $t + ['type' => QueryInterface::JOIN_TYPE_INNER, 'alias' => $alias];
}
if ($overwrite) {
@@ -683,7 +684,7 @@ public function removeJoin($name)
*/
public function leftJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, 'LEFT'), $types);
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_LEFT), $types);
}
/**
@@ -703,7 +704,7 @@ public function leftJoin($table, $conditions = [], $types = [])
*/
public function rightJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, 'RIGHT'), $types);
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_RIGHT), $types);
}
/**
@@ -723,7 +724,7 @@ public function rightJoin($table, $conditions = [], $types = [])
*/
public function innerJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, 'INNER'), $types);
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_INNER), $types);
}
/**
@@ -23,6 +23,10 @@
interface QueryInterface
{
const JOIN_TYPE_INNER = 'INNER';
const JOIN_TYPE_LEFT = 'LEFT';
const JOIN_TYPE_RIGHT = 'RIGHT';
/**
* Returns a key => value array representing a single aliased field
* that can be passed directly to the select() method.
@@ -19,6 +19,7 @@
use Cake\Core\ConventionsTrait;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\QueryInterface;
use Cake\Datasource\ResultSetDecorator;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\Utility\Inflector;
@@ -158,7 +159,7 @@ abstract class Association
*
* @var string
*/
protected $_joinType = 'LEFT';
protected $_joinType = QueryInterface::JOIN_TYPE_LEFT;
/**
* The property name that should be filled with data from the target table
@@ -18,6 +18,7 @@
use Cake\Database\ExpressionInterface;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\QueryInterface;
use Cake\ORM\Association;
use Cake\ORM\Association\Loader\SelectWithPivotLoader;
use Cake\ORM\Query;
@@ -55,7 +56,7 @@ class BelongsToMany extends Association
*
* @var string
*/
protected $_joinType = 'INNER';
protected $_joinType = QueryInterface::JOIN_TYPE_INNER;
/**
* The strategy name to be used to fetch associated records.
@@ -1120,7 +1121,7 @@ protected function _appendJunctionJoin($query, $conditions)
$name => [
'table' => $this->junction()->getTable(),
'conditions' => $conditions,
'type' => 'INNER'
'type' => QueryInterface::JOIN_TYPE_INNER
]
];
@@ -19,6 +19,7 @@
use Cake\Database\Expression\FieldInterface;
use Cake\Database\Expression\QueryExpression;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\QueryInterface;
use Cake\ORM\Association;
use Cake\ORM\Association\DependentDeleteHelper;
use Cake\ORM\Association\Loader\SelectLoader;
@@ -47,7 +48,7 @@ class HasMany extends Association
*
* @var string
*/
protected $_joinType = 'INNER';
protected $_joinType = QueryInterface::JOIN_TYPE_INNER;
/**
* The strategy name to be used to fetch associated records.
@@ -17,6 +17,7 @@
use ArrayObject;
use Cake\Collection\Collection;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\QueryInterface;
use Cake\Event\Event;
use Cake\I18n\I18n;
use Cake\ORM\Behavior;
@@ -173,7 +174,7 @@ public function setupFieldAssociations($fields, $table, $model, $strategy)
$this->_table->hasOne($name, [
'targetTable' => $fieldTable,
'foreignKey' => 'foreign_key',
'joinType' => $filter ? 'INNER' : 'LEFT',
'joinType' => $filter ? QueryInterface::JOIN_TYPE_INNER : QueryInterface::JOIN_TYPE_LEFT,
'conditions' => $conditions,
'propertyName' => $field . '_translation'
]);
@@ -246,7 +247,7 @@ public function beforeFind(Event $event, Query $query, $options)
);
if ($changeFilter) {
$filter = $options['filterByCurrentLocale'] ? 'INNER' : 'LEFT';
$filter = $options['filterByCurrentLocale'] ? QueryInterface::JOIN_TYPE_INNER : QueryInterface::JOIN_TYPE_LEFT;
$contain[$name]['joinType'] = $filter;
}
}
@@ -16,6 +16,7 @@
use Cake\Database\Statement\BufferedStatement;
use Cake\Database\Statement\CallbackStatement;
use Cake\Datasource\QueryInterface;
use Closure;
use InvalidArgumentException;
@@ -238,7 +239,7 @@ public function setMatching($assoc, callable $builder = null, $options = [])
}
if (!isset($options['joinType'])) {
$options['joinType'] = 'INNER';
$options['joinType'] = QueryInterface::JOIN_TYPE_INNER;
}
$assocs = explode('.', $assoc);
@@ -573,7 +573,7 @@ public function leftJoinWith($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()
->setMatching($assoc, $builder, [
'joinType' => 'LEFT',
'joinType' => QueryInterface::JOIN_TYPE_LEFT,
'fields' => false
])
->getMatching();
@@ -622,7 +622,7 @@ public function innerJoinWith($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()
->setMatching($assoc, $builder, [
'joinType' => 'INNER',
'joinType' => QueryInterface::JOIN_TYPE_INNER,
'fields' => false
])
->getMatching();
@@ -686,7 +686,7 @@ public function notMatching($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()
->setMatching($assoc, $builder, [
'joinType' => 'LEFT',
'joinType' => QueryInterface::JOIN_TYPE_LEFT,
'fields' => false,
'negateMatch' => true
])

0 comments on commit d5ae641

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