mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix updating of manyToMany relationships
This commit is contained in:
parent
5e6833975b
commit
4cea678e93
@ -45,7 +45,6 @@ class AccompanyingPeriodWorkDuplicateController extends AbstractController
|
|||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
dump($form->get('acpw')->getData());
|
|
||||||
$acpw2 = $this->accompanyingPeriodWorkRepository->find($form->get('acpw')->getData());
|
$acpw2 = $this->accompanyingPeriodWorkRepository->find($form->get('acpw')->getData());
|
||||||
|
|
||||||
$direction = $form->get('direction')->getData();
|
$direction = $form->get('direction')->getData();
|
||||||
|
@ -173,10 +173,21 @@ class AccompanyingPeriodWorkMergeService
|
|||||||
];
|
];
|
||||||
} elseif (8 === $assoc['type'] && isset($assoc['joinTable'])) {
|
} elseif (8 === $assoc['type'] && isset($assoc['joinTable'])) {
|
||||||
if ($assoc['isOwningSide']) {
|
if ($assoc['isOwningSide']) {
|
||||||
|
dump($assoc);
|
||||||
$joinTable = $assoc['joinTable']['name'];
|
$joinTable = $assoc['joinTable']['name'];
|
||||||
$joinColumn = $assoc['joinTable']['joinColumns'][0]['name'];
|
$joinColumn = $assoc['joinTable']['joinColumns'][0]['name'];
|
||||||
|
$relationColumn = $assoc['joinTable']['inverseJoinColumns'][0]['name'];
|
||||||
$queries[] = [
|
$queries[] = [
|
||||||
'sql' => "UPDATE {$joinTable} SET {$joinColumn} = :toKeep WHERE {$joinColumn} = :toDelete AND NOT EXISTS (SELECT 1 FROM {$joinTable} WHERE {$joinColumn} = :toKeep)",
|
'sql' => "
|
||||||
|
UPDATE {$joinTable} SET {$joinColumn} = :toKeep
|
||||||
|
WHERE {$joinColumn} = :toDelete
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM {$joinTable} AS t2
|
||||||
|
WHERE t2.{$joinColumn} = :toKeep
|
||||||
|
AND t2.{$relationColumn} = {$joinTable}.{$relationColumn}
|
||||||
|
)
|
||||||
|
",
|
||||||
'params' => ['toDelete' => $toDelete->getId(), 'toKeep' => $toKeep->getId()],
|
'params' => ['toDelete' => $toDelete->getId(), 'toKeep' => $toKeep->getId()],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user