3

I am using stof/doctrineExtensionsBundle v1.3 with Symfony v4.2.4, having some trouble setting up the Sortable extension. I have installed the bundle using Symfony flex:

composer require stof/doctrine-extensions-bundle

After that I activated Sortable in config\packages\stof_doctrine_extensions.yaml, as mentioned in the official documentation:

// config/packages/stof_doctrine_extensions.yaml

stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            sortable: true

I have got an Entity named PhotoSeries which I have already rigged with @SortablePosition and @SortableGroup:

// Entity/Portfolio/PhotoSeries.php

...

/**
 * @ORM\Column(type="integer", length=8)
 * @Gedmo\SortablePosition
 */
private $position;

/**
 * @ORM\ManyToOne(targetEntity="PhotoAlbum", inversedBy="series")
 * @ORM\JoinColumn(name="id_album", referencedColumnName="id")
 * @Gedmo\SortableGroup
 */
private $album;

...

The actual update of sorting positions is now done by an ajax call to the following controller method:

// src/Controller/BackendImageryController.php

...

/**
 * @Route("/series/sort/{id}/{newPosition}", name="sort_series", requirements={ "id": "\d+", "newPosition": "\d+" }, defaults={"id":0, "newPosition":0}, methods={"PATCH"}, condition="request.isXmlHttpRequest()")
 * @param int $id
 * @param int $newPosition
 * @return Response
 * @throws
 */
public function ajaxSortSeries($id, $newPosition)
{
    $em = $this->getDoctrine()->getManager();

    $series = $this
        ->getDoctrine()
        ->getRepository(PhotoSeries::class)
        ->find($id);

    $series->setPosition($newPosition);

    $em->persist($series);
    $em->flush();

    return new Response('true');
}

Unfortunately, when I look into the Doctrine part of the Symfony Profiler of that call, it only does the following:

...

SELECT MAX(p0_.position) AS sclr_0 FROM photo_series p0_ WHERE p0_.id_album = ?
(Parameters: 6)

START TRANSACTION

UPDATE photo_series SET position = ? WHERE id = ?
(Parameters: 0, 6)

COMMIT

And that's all, no updating of the other entities (within the same SortableGroup). Am I missing something important or may it be a compatibility issue with Symfony 4.1?

Dominik
  • 31
  • 4
  • Welcome to stackoverflow. Why do you persist an already persitend entity? you can remove that. Do you use the SortableRepository? @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository") – Rufinus Mar 16 '19 at 12:29
  • The $em->persist() is not necessary in this case, I know. I just put it in for clarification. I do not use the SortableRepository right now – maybe later, if I need some of its methods. – Dominik Mar 16 '19 at 15:14

0 Answers0