Sortable是否与Symfony 4.2(使用stof / doctrineExtensionsBundle)兼容?

时间:2019-03-16 11:04:09

标签: symfony doctrine symfony4 doctrine-extensions stofdoctrineextensions

我正在将stof / doctrineExtensionsBundle v1.3与Symfony v4.2.4一起使用,在设置Sortable扩展时遇到了一些麻烦。我已经使用Symfony flex安装了捆绑软件:

composer require stof/doctrine-extensions-bundle

此后,我在config \ packages \ stof_doctrine_extensions.yaml中激活了Sortable,如official documentation中所述:

// config/packages/stof_doctrine_extensions.yaml

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

我有一个名为PhotoSeries的实体,已经使用@SortablePosition和@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;

...

排序位置的实际更新现在通过对以下控制器方法的ajax调用完成:

// 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');
}

不幸的是,当我查看该调用的Symfony Profiler的“教义”部分时,它仅执行以下操作:

...

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

仅此而已,无需更新其他实体(在同一SortableGroup中)。我是否缺少重要的东西,或者可能是Symfony 4.1的兼容性问题?

0 个答案:

没有答案