Skip to content
Permalink
Browse files

Update HasMany to avoid ambigous columns

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
Jesper Skytte Hansen committed Mar 3, 2016
1 parent a148462 commit 54d8e7683243f62e8ce55c53906e3c9ea4bd6b04
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/ORM/Association/HasMany.php
@@ -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;
@@ -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) {

0 comments on commit 54d8e76

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