addDefaultTypes() public method

This method returns the same query object for chaining.
public addDefaultTypes ( Table $table )
$table Table The table to pull types from
Exemplo n.º 1
0
 /**
  * Append a join to the junction table.
  *
  * @param \Cake\ORM\Query $query The query to append.
  * @param string|array $conditions The query conditions to use.
  * @return \Cake\ORM\Query The modified query.
  */
 protected function _appendJunctionJoin($query, $conditions)
 {
     $name = $this->_junctionAssociationName();
     $joins = $query->join();
     $matching = [$name => ['table' => $this->junction()->table(), 'conditions' => $conditions, 'type' => 'INNER']];
     $assoc = $this->target()->association($name);
     $query->addDefaultTypes($assoc->target())->join($matching + $joins, [], true);
     $query->eagerLoader()->addToJoinsMap($name, $assoc);
     return $query;
 }
Exemplo n.º 2
0
 /**
  * Helper function used to conditionally append fields to the select clause of
  * a query from the fields found in another query object.
  *
  * @param \Cake\ORM\Query $query the query that will get the fields appended to
  * @param \Cake\ORM\Query $surrogate the query having the fields to be copied from
  * @param array $options options passed to the method `attachTo`
  * @return void
  */
 protected function _appendFields($query, $surrogate, $options)
 {
     if ($query->eagerLoader()->autoFields() === false) {
         return;
     }
     $fields = $surrogate->clause('select') ?: $options['fields'];
     $target = $this->_targetTable;
     $autoFields = $surrogate->autoFields();
     if (empty($fields) && !$autoFields) {
         if ($options['includeFields'] && ($fields === null || $fields !== false)) {
             $fields = $target->schema()->columns();
         }
     }
     if ($autoFields === true) {
         $fields = array_merge((array) $fields, $target->schema()->columns());
     }
     if (!empty($fields)) {
         $query->select($query->aliasFields($fields, $target->alias()));
     }
     $query->addDefaultTypes($target);
 }