Skip to content

Commit

Permalink
Not using union, but OR conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 28, 2014
1 parent b8eeb55 commit 700c493
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/ORM/Marshaller.php
Expand Up @@ -384,17 +384,14 @@ public function mergeMany($entities, array $data, array $options = []) {
->map(function ($data, $key) {
return explode(';', $key);
})
->filter(function ($data) use ($primary) {
return count(array_filter($data, 'strlen')) === count($primary);
->filter(function ($keys) use ($primary) {
return count(array_filter($keys, 'strlen')) === count($primary);
})
->map(function ($keys) use ($primary) {
return $this->_table->find()->where(array_combine($primary, $keys));
})
->reduce(function ($result, $query) {
return $result === null ? $query : $result->union($query);
}, null);
->reduce(function ($query, $keys) use ($primary) {
return $query->orWhere($query->newExpr()->and_(array_combine($primary, $keys)));
}, $this->_table->find());

if ($maybeExistentQuery) {
if (count($maybeExistentQuery->clause('where'))) {
foreach ($maybeExistentQuery as $entity) {
$key = implode(';', $entity->extract($primary));
$output[] = $this->merge($entity, $indexed[$key], $options);
Expand Down

0 comments on commit 700c493

Please sign in to comment.