Doctrine Extensions当更改位置超过1时,可排序无法正常工作

Rai*_*eru 10 php symfony doctrine-extensions stofdoctrineextensions

我使用Symfony 3.1 + Doctrine GEDMO扩展(通过StofDoctrineExtensionsBundle).我已将我的实体设置为具有可排序行为:

<?php

namespace AppBundle\Entity\Manual;

use AppBundle\Entity\Identifier;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Table(name="manual_pages")
 * @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
 */
class Manual
{
    use Identifier;

    /**
     * @ORM\Column(type="string")
     * @Assert\NotBlank(message="Toto pole musí být vypln?no")
     */
    private $title;

    /**
     * @ORM\Column(type="text")
     * @Assert\NotBlank(message="Toto pole musí být vypln?no")
     */
    private $content;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Manual\ManualImage", mappedBy="manual")
     * @ORM\OrderBy({"position"="ASC"})
     */
    private $images;

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

    /**
     * @return mixed
     */
    public function getPosition()
    {
        return $this->position;
    }

    /**
     * @param mixed $position
     */
    public function setPosition($position)
    {
        $this->position = $position;
    }


    /**
     * @return mixed
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @param mixed $title
     */
    public function setTitle($title)
    {
        $this->title = $title;
    }

    /**
     * @return ManualImage[]
     */
    public function getImages()
    {
        return $this->images;
    }

    /**
     * @param ManualImage[] $images
     */
    public function setImages($images)
    {
        $this->images = $images;
    }

    /**
     * @return mixed
     */
    public function getContent()
    {
        return $this->content;
    }

    /**
     * @param mixed $content
     */
    public function setContent($content)
    {
        $this->content = $content;
    }


}
Run Code Online (Sandbox Code Playgroud)

当我继续改变位置时,排序行为表现良好:

$entity->setPosition($entity->getPosition() + 1);
// or
$entity->setPosition($entity->getPosition() - 1);
Run Code Online (Sandbox Code Playgroud)

但是当我实现JS拖放来改变位置时,整个事情变得奇怪了.例如,有这个表:

id    | position
1     | 0
2     | 1
3     | 2
4     | 3
5     | 4
6     | 5
Run Code Online (Sandbox Code Playgroud)

当我为id为6的行做这个:

$newPosition = $entity->getPosition() - 5; // = 0
$entity->setPosition($newPosition);
Run Code Online (Sandbox Code Playgroud)

表格改为:

id    | position
1     | 2
2     | 3
3     | 4
4     | 5
5     | 5
6     | 0
Run Code Online (Sandbox Code Playgroud)

位置1没有任何东西,但位置5被占用两次.有任何想法吗?

Nic*_*o M 7

我们很久以前也发现了这个错误。在我们的情况下,当您同时/刷新设置多个位置时出现问题。我们最终使用了没有gedmo扩展名的javascript完整排序顺序,因为单次刷新太昂贵了。

也请查看以下可能相关的错误问题: