Skip to content

Commit

Permalink
Merge pull request #1279 from leonex-cstoller/fix_position_update
Browse files Browse the repository at this point in the history
Fixing issue in exclusion of new entities when positions are updated.
  • Loading branch information
l3pp4rd committed Apr 8, 2015
2 parents 251c0a1 + 1f538cb commit 0f130d2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Gedmo/Sortable/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ public function updatePositions($relocation, $delta, $config)
$meta = $this->getObjectManager()->getClassMetadata($relocation['name']);
if (count($meta->identifier) == 1) {
// if we only have one identifier, we can use IN syntax, for better performance
$params['excluded'] = array();
$excludedIds = array();
foreach ($delta['exclude'] as $entity) {
$params['excluded'][] = $meta->getFieldValue($entity, $meta->identifier[0]);
if ($id = $meta->getFieldValue($entity, $meta->identifier[0])) {
$excludedIds[] = $id;
}
}
if (!empty($excludedIds)) {
$params['excluded'] = $excludedIds;
$dql .= " AND n.{$meta->identifier[0]} NOT IN (:excluded)";
}
$dql .= " AND n.{$meta->identifier[0]} NOT IN (:excluded)";
} else if (count($meta->identifier) > 1) {
foreach ($delta['exclude'] as $entity) {
$j = 0;
Expand Down

0 comments on commit 0f130d2

Please sign in to comment.