Skip to content
Snippets Groups Projects
Commit cf6add41 authored by Jonathan Foucher's avatar Jonathan Foucher
Browse files

remove current item from self referencing linkable items. Fixes...

remove current item from self referencing linkable items. Fixes #970
parent c984e7f3
No related branches found
No related tags found
No related merge requests found
Pipeline #84841 passed
...@@ -34,7 +34,7 @@ class LinkableType extends AbstractType ...@@ -34,7 +34,7 @@ class LinkableType extends AbstractType
'multiple' => true, 'multiple' => true,
'expanded' => false, 'expanded' => false,
'by_reference' => false, 'by_reference' => false,
'query_builder' => function (EntityRepository $er) use ($object, $orderField) { 'query_builder' => function (EntityRepository $er) use ($object, $orderField, $class) {
$collectivity = null; $collectivity = null;
if (!\is_null($object) && $object instanceof CollectivityRelated && !\is_null($object->getCollectivity())) { if (!\is_null($object) && $object instanceof CollectivityRelated && !\is_null($object->getCollectivity())) {
$collectivity = $object->getCollectivity(); $collectivity = $object->getCollectivity();
...@@ -51,9 +51,15 @@ class LinkableType extends AbstractType ...@@ -51,9 +51,15 @@ class LinkableType extends AbstractType
} elseif ($orderField) { } elseif ($orderField) {
$qb->addOrderBy('c.' . $orderField, 'asc'); $qb->addOrderBy('c.' . $orderField, 'asc');
} }
if ($object instanceof $class) {
// self referencing, remove current object from query
$qb->andWhere('c != :self')
->setParameter('self', $object)
;
}
if ($collectivity) { if ($collectivity) {
return $qb return $qb
->where('c.collectivity = :collectivity') ->andWhere('c.collectivity = :collectivity')
->setParameter('collectivity', $collectivity) ->setParameter('collectivity', $collectivity)
; ;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment