Skip to content
Permalink
Browse files

Fixed test when using identifier quoting

  • Loading branch information...
lorenzo committed Mar 6, 2016
1 parent c7af5e8 commit 4363b58451a8af6cec76f6ad4cae2d405c50140d
Showing with 31 additions and 9 deletions.
  1. +31 −9 src/ORM/Association/SelectableAssociationTrait.php
@@ -110,18 +110,40 @@ protected function _buildQuery($options)
$fetchQuery = $options['queryBuilder']($fetchQuery);
}
$this->_assertFieldsPresent($fetchQuery, (array)$key);
return $fetchQuery;
}
/**
* Checks that the fetching query either has auto fields on or
* has the foreignKey fields selected.
* If the required fields are missing, throws an exception.
*
* @param \Cake\ORM\Query The association fetching query
* @param array $key The foreign key fields to check
* @return void
* @throws InvalidArgumentException
*/
protected function _assertFieldsPresent($fetchQuery, $key)
{
$select = $fetchQuery->clause('select');
if (!empty($select)) {
$select = $fetchQuery->aliasFields($select);
if (array_diff((array)$key, $select) !== []) {
throw new InvalidArgumentException(
sprintf('You are required to select the "%s" field(s)',
implode(', ', (array)$key)
));
}
if (empty($select)) {
return;
}
$missingFields = array_diff($key, $select) !== [];
return $fetchQuery;
if ($missingFields) {
$driver = $fetchQuery->connection()->driver();
$key = array_map([$driver, 'quoteIdentifier'], $key);
$missingFields = array_diff($key, $select) !== [];
}
if ($missingFields) {
throw new InvalidArgumentException(
sprintf('You are required to select the "%s" field(s)',
implode(', ', (array)$key)
));
}
}
/**

0 comments on commit 4363b58

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