|
|
@@ -43,6 +43,7 @@ use Cake\ORM\Exception\PersistenceFailedException;
|
|
|
use Cake\ORM\Exception\RolledbackTransactionException;
|
|
|
use Cake\ORM\Query\DeleteQuery;
|
|
|
use Cake\ORM\Query\InsertQuery;
|
|
|
+use Cake\ORM\Query\QueryFactory;
|
|
|
use Cake\ORM\Query\UpdateQuery;
|
|
|
use Cake\ORM\Rule\IsUnique;
|
|
|
use Cake\Utility\Inflector;
|
|
|
@@ -259,6 +260,8 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
|
|
|
*/
|
|
|
protected ?string $_registryAlias = null;
|
|
|
|
|
|
+ protected QueryFactory $queryFactory;
|
|
|
+
|
|
|
/**
|
|
|
* Initializes a new instance
|
|
|
*
|
|
|
@@ -278,7 +281,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
|
|
|
* validation set, or an associative array, where key is the name of the
|
|
|
* validation set and value the Validator instance.
|
|
|
*
|
|
|
- * @param array<string, mixed> $config List of options for this table
|
|
|
+ * @param array<string, mixed> $config List of options for this table.
|
|
|
*/
|
|
|
public function __construct(array $config = [])
|
|
|
{
|
|
|
@@ -294,6 +297,9 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
|
|
|
if (!empty($config['connection'])) {
|
|
|
$this->setConnection($config['connection']);
|
|
|
}
|
|
|
+ if (!empty($config['queryFactory'])) {
|
|
|
+ $this->queryFactory = $config['queryFactory'];
|
|
|
+ }
|
|
|
if (!empty($config['schema'])) {
|
|
|
$this->setSchema($config['schema']);
|
|
|
}
|
|
|
@@ -323,6 +329,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
|
|
|
$this->_behaviors = $behaviors ?: new BehaviorRegistry();
|
|
|
$this->_behaviors->setTable($this);
|
|
|
$this->_associations = $associations ?: new AssociationCollection();
|
|
|
+ $this->queryFactory ??= new QueryFactory($this->getConnection(), $this);
|
|
|
|
|
|
$this->initialize($config);
|
|
|
$this->_eventManager->on($this);
|
|
|
@@ -1689,7 +1696,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
|
|
|
*/
|
|
|
public function query(): Query
|
|
|
{
|
|
|
- return new Query($this->getConnection(), $this);
|
|
|
+ return $this->queryFactory->select();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1699,7 +1706,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
|
|
|
*/
|
|
|
public function insertQuery(): InsertQuery
|
|
|
{
|
|
|
- return new InsertQuery($this->getConnection(), $this);
|
|
|
+ return $this->queryFactory->insert();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1709,7 +1716,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
|
|
|
*/
|
|
|
public function updateQuery(): UpdateQuery
|
|
|
{
|
|
|
- return new UpdateQuery($this->getConnection(), $this);
|
|
|
+ return $this->queryFactory->update();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1719,18 +1726,19 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
|
|
|
*/
|
|
|
public function deleteQuery(): DeleteQuery
|
|
|
{
|
|
|
- return new DeleteQuery($this->getConnection(), $this);
|
|
|
+ return $this->queryFactory->delete();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Creates a new Query::subquery() instance for a table.
|
|
|
+ * Creates a new Query instance with field auto aliasing disabled.
|
|
|
+ *
|
|
|
+ * This is useful for subqueries.
|
|
|
*
|
|
|
* @return \Cake\ORM\Query
|
|
|
- * @see \Cake\ORM\Query::subquery()
|
|
|
*/
|
|
|
public function subquery(): Query
|
|
|
{
|
|
|
- return Query::subquery($this);
|
|
|
+ return $this->queryFactory->select()->disableAutoAliasing();
|
|
|
}
|
|
|
|
|
|
/**
|