php – Doctrine Extensions更改位置超过1时,可排序无法正常工作
发布时间:2020-12-13 13:04:01 所属栏目:PHP教程 来源:网络整理
导读:我正在使用Symfony 3.1 Doctrine GEDMO扩展(通过StofDoctrineExtensionsBundle).我已将我的实体设置为具有可排序行为: ?phpnamespace AppBundleEntityManual;use AppBundleEntityIdentifier;use DoctrineORMMapping as ORM;use SymfonyComponentVal
|
我正在使用Symfony 3.1 Doctrine GEDMO扩展(通过StofDoctrineExtensionsBundle).我已将我的实体设置为具有可排序行为:
<?php
namespace AppBundleEntityManual;
use AppBundleEntityIdentifier;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use GedmoMappingAnnotation as Gedmo;
/**
* @ORMTable(name="manual_pages")
* @ORMEntity(repositoryClass="GedmoSortableEntityRepositorySortableRepository")
*/
class Manual
{
use Identifier;
/**
* @ORMColumn(type="string")
* @AssertNotBlank(message="Toto pole musí byt vyplněno")
*/
private $title;
/**
* @ORMColumn(type="text")
* @AssertNotBlank(message="Toto pole musí byt vyplněno")
*/
private $content;
/**
* @ORMOneToMany(targetEntity="AppBundleEntityManualManualImage",mappedBy="manual")
* @ORMOrderBy({"position"="ASC"})
*/
private $images;
/**
* @GedmoSortablePosition
* @ORMColumn(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;
}
}
当我继续改变位置时,排序行为表现良好: $entity->setPosition($entity->getPosition() + 1); // or $entity->setPosition($entity->getPosition() - 1); 但是当我实现JS拖放以改变位置时,整个事情变得奇怪.例如,有这个表: id | position 1 | 0 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 当我为id为6的行做时: $newPosition = $entity->getPosition() - 5; // = 0 $entity->setPosition($newPosition); 表格改为: id | position 1 | 2 2 | 3 3 | 4 4 | 5 5 | 5 6 | 0 位置1没有任何东西,但位置5被占用两次.有任何想法吗?
我们很久以前就发现了这个bug.在我们的情况下,当您同时设置多个位置/刷新时出现问题.我们最终使用了没有gedmo扩展名的javascript的完整排序顺序,因为单次刷新太贵了.
另请查看以下可能相关的错误问题: > https://github.com/Atlantic18/DoctrineExtensions/issues/1642(“更新问题”) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
