Skip to content

Commit

Permalink
Update HasMany to avoid ambigous columns
Browse files Browse the repository at this point in the history
I've changed the conditions from a basic array to a QueryExpression,
which I aftewards traverse to add alias to all fields.
  • Loading branch information
Jesper Skytte Hansen committed Mar 3, 2016
1 parent a148462 commit 54d8e76
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ORM/Association/HasMany.php
Expand Up @@ -16,6 +16,8 @@
namespace Cake\ORM\Association;

use Cake\Collection\Collection;
use Cake\Database\Expression\FieldInterface;
use Cake\Database\Expression\QueryExpression;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Association;
use Cake\ORM\Table;
Expand Down Expand Up @@ -436,6 +438,12 @@ protected function _unlink(array $foreignKey, Table $target, array $conditions =

if ($mustBeDependent) {
if ($this->_cascadeCallbacks) {
$conditions = new QueryExpression($conditions);
$conditions->traverse(function ($entry) use ($target) {
if ($entry instanceof FieldInterface) {
$entry->setField($target->aliasField($entry->getField()));
}
});
$query = $this->find('all')->where($conditions);
$ok = true;
foreach ($query as $assoc) {
Expand Down

0 comments on commit 54d8e76

Please sign in to comment.