Php 拉姆齐\UUID不与OneTONE协会合作
我正在为我在Symfony 3的团队构建一个项目管理工具。我使用的是系统中的ID 到目前为止,一对多或多对一关联没有问题,但当我尝试持久化一对一关联时,原则并没有将关联实体转换为其UUID,而是在SQL中保留一个Php 拉姆齐\UUID不与OneTONE协会合作,php,symfony,doctrine-orm,uuid,Php,Symfony,Doctrine Orm,Uuid,我正在为我在Symfony 3的团队构建一个项目管理工具。我使用的是系统中的ID 到目前为止,一对多或多对一关联没有问题,但当我尝试持久化一对一关联时,原则并没有将关联实体转换为其UUID,而是在SQL中保留一个null值 在这个例子中,我有一个WikiPage,它可以有多个WikiPageVersions。WikiPage与WikiPageVersion有一对多的关联(对于页面的所有版本,versions属性:但是对于当前版本,currentVersion属性:也有一对一()的关联) Wiki
null
值
在这个例子中,我有一个WikiPage,它可以有多个WikiPageVersions。WikiPage与WikiPageVersion有一对多的关联(对于页面的所有版本,versions
属性:但是对于当前版本,currentVersion
属性:也有一对一()的关联)
WikiPage还与Project有多对一关联(用于跟踪wiki页用于哪个项目),并且该属性已正确填充
维基页面实体
/**
* @ORM\Table(name="wiki_page")
* @ORM\Entity(repositoryClass="AppBundle\Repository\Project\WikiPageRepository")
*/
class WikiPage
{
/**
* @var Uuid
* @ORM\Id
* @ORM\Column(type="uuid")
*/
protected $id;
/**
* @var Project
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Project\Project", inversedBy="wikiPages")
* @ORM\JoinColumn(name="project_id", referencedColumnName="id")
*/
protected $project;
/**
* @var string
* @ORM\Column(name="title", type="text")
* @Assert\NotBlank()
*/
protected $title;
/**
* @var HiveWikiPageVersion
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Project\WikiPageVersion", fetch="EAGER")
*/
protected $currentVersion;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Project\WikiPageVersion", mappedBy="wikiPage", cascade={"persist", "remove"})
*/
protected $versions;
// -- Class Methods
}
/**
* @ORM\Table(name="wiki_page_version")
* @ORM\Entity(repositoryClass="AppBundle\Repository\Project\WikiPageVersionRepository")
*/
class WikiPageVersion
{
/**
* @var Uuid
* @ORM\Id
* @ORM\Column(type="uuid")
*/
protected $id;
/**
* @var WikiPage
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Project\WikiPage", inversedBy="versions")
* @ORM\JoinColumn(name="wiki_page_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $wikiPage;
/**
* @var string
* @ORM\Column(name="content", type="text")
* @Assert\NotBlank()
*/
protected $content;
/**
* @var string
* @ORM\Column(name="version_comment", type="string", length=255)
* @Assert\NotNull()
*/
protected $versionComment;
/**
* @var HiveWikiPageVersion
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Project\WikiPageVersion")
* @ORM\JoinColumn(name="previous_version", referencedColumnName="id")
* @Assert\Type(type="Odev\Hive\Model\Entity\Project\WikiPageVersion")
*/
protected $previousVersion;
/**
* @var \DateTimeInterface
* @ORM\Column(name="created", type="datetime")
* @Assert\NotBlank()
*/
protected $created;
/**
* @var User
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* @ORM\JoinColumn(name="created_by", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $createdBy;
}
// -- Methods
WikiPageVersion实体
/**
* @ORM\Table(name="wiki_page")
* @ORM\Entity(repositoryClass="AppBundle\Repository\Project\WikiPageRepository")
*/
class WikiPage
{
/**
* @var Uuid
* @ORM\Id
* @ORM\Column(type="uuid")
*/
protected $id;
/**
* @var Project
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Project\Project", inversedBy="wikiPages")
* @ORM\JoinColumn(name="project_id", referencedColumnName="id")
*/
protected $project;
/**
* @var string
* @ORM\Column(name="title", type="text")
* @Assert\NotBlank()
*/
protected $title;
/**
* @var HiveWikiPageVersion
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Project\WikiPageVersion", fetch="EAGER")
*/
protected $currentVersion;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Project\WikiPageVersion", mappedBy="wikiPage", cascade={"persist", "remove"})
*/
protected $versions;
// -- Class Methods
}
/**
* @ORM\Table(name="wiki_page_version")
* @ORM\Entity(repositoryClass="AppBundle\Repository\Project\WikiPageVersionRepository")
*/
class WikiPageVersion
{
/**
* @var Uuid
* @ORM\Id
* @ORM\Column(type="uuid")
*/
protected $id;
/**
* @var WikiPage
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Project\WikiPage", inversedBy="versions")
* @ORM\JoinColumn(name="wiki_page_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $wikiPage;
/**
* @var string
* @ORM\Column(name="content", type="text")
* @Assert\NotBlank()
*/
protected $content;
/**
* @var string
* @ORM\Column(name="version_comment", type="string", length=255)
* @Assert\NotNull()
*/
protected $versionComment;
/**
* @var HiveWikiPageVersion
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Project\WikiPageVersion")
* @ORM\JoinColumn(name="previous_version", referencedColumnName="id")
* @Assert\Type(type="Odev\Hive\Model\Entity\Project\WikiPageVersion")
*/
protected $previousVersion;
/**
* @var \DateTimeInterface
* @ORM\Column(name="created", type="datetime")
* @Assert\NotBlank()
*/
protected $created;
/**
* @var User
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* @ORM\JoinColumn(name="created_by", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $createdBy;
}
// -- Methods
到目前为止的故障排除
[Doctrine\DBAL\Exception\NotNullConstraintViolationException]
An exception occurred while executing 'INSERT INTO wiki_page (id, project_home, title, project_id, current_version_id) VALUES (?, ?, ?, ?, ?)' with params ["ddc1f51a-f5d9-489f-89bb-cd79f3393af0", 1
, "Technical Reviews Wiki", "5138b185-b10b-48ac-a102-bdea1139c911", null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'current_version_id' cannot be null
以及异常跟踪(此异常是在装置加载期间保存的):
在这一点上,我迷路了——如果有任何关于我应该去哪里寻找的建议,或者如果有其他人遇到了这个问题,我会很乐意接受这些建议和指导
更新
应马特奥的要求:
这里是fixture的load
方法,它创建记录并抛出错误
/**
* {@inheritDoc}
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
// Create ODEV Project Section
$section = new ProjectSection(
Uuid::uuid4(),
'ODEV',
'ODEV specific projects'
);
$manager->persist($section);
$this->addReference('section-odev', $section);
// Create Technical Review Project -> public
$project = new Project(
Uuid::uuid4(),
'techreview',
$section,
'Technical Reviews',
'Technical Reviews for Work Requests',
false,
false,
$this->getReference('user-system'),
$this->getReference('user-system'),
'',
$this->getReference('user-system')
);
// VarDumper::dump($project->getWikiHome()->getId());
// VarDumper::dump($project->getCreatedBy()->getId());
$manager->persist($project);
$this->addReference('project-tech-review', $project);
$manager->flush();
}
两个VarDumper::dump()
命令用于确认正在创建关联
实际的WikiPage在项目的构造函数中生成,WikiPageVersion在WikiPages的构造函数中生成
以下是项目的构造函数:
public function __construct(
string $id,
string $identifier,
ProjectSection $section,
string $name,
string $description,
bool $private,
bool $sensitive,
User $owner,
User $contact,
string $homepage,
User $createdBy
) {
$this->id = Uuid::fromString($id);
$this->identifier = $identifier;
$this->projectSection = $section;
$this->name = $name;
$this->description = $description;
$this->private = $private;
$this->sensitive = $sensitive;
$this->owner = $owner;
$this->contact = $contact;
$this->homepage = $homepage;
$this->createdBy = $createdBy;
$this->created = new \DateTimeImmutable();
$this->updatedBy = $createdBy;
$this->updated = new \DateTimeImmutable();
$this->archived = false;
$this->workRequest = null;
// set up collections
$this->teamMembers = new ArrayCollection();
$this->issues = new ArrayCollection();
$this->folders = new ArrayCollection($this->defaultFolders());
$this->wikiHome = $this->defaultWikiPage();
$this->wikiPages = new ArrayCollection([$this->wikiHome]);
$this->labels = new ArrayCollection($this->defaultLabels());
$this->milestones = new ArrayCollection($this->defaultMilestones());
}
protected function defaultWikiPage(): WikiPage
{
return new WikiPage(Uuid::uuid4(), $this, $this->name.' Wiki', '', $this->createdBy);
}
以及WikiPage
的构造函数:
public function __construct(string $id, Project $project, string $title, string $content, User $createdBy)
{
$this->id = Uuid::fromString($id);
$this->project = $project;
$this->title = $title;
$this->content = $content;
$this->created = new \DateTimeImmutable();
$this->createdBy = $createdBy;
$this->currentVersion = $this->createFirstVersion($content, $createdBy);
$this->versions = new ArrayCollection([$this->currentVersion]);
}
protected function createFirstVersion(string $content, User $createdBy)
{
return new WikiPageVersion(Uuid::uuid4(), $this, $content, $createdBy, 'Page Created');
}
希望有帮助。当WikiPage实体尝试插入时,它正在尝试插入其所有属性。检查版本,如果===null,则取消设置键索引。那么当
INSERT触发parm数组只有4个键。当WikiPage实体尝试插入时,它正在尝试插入其所有属性。检查版本,如果===null,则取消设置键索引。那么当
INSERT激发parm数组只有4个键。您可以分享有关处理关系的代码吗?广告示例fixturesCan的代码您共享关于处理关系的代码吗?例如,fixtures的代码不符合您所说的。我不是在做一个直接的插入-这是由条令处理的。条令应该将WikiPageVersion转换为对象的ID属性(因为条令在flush()
期间生成INSERT语句时有@ORM\ID
注释)。此过程适用于除OneTONE关联之外的所有其他关联。现在我明白了,遗憾的是没有解决方案:(.我不明白你说的。我没有直接插入-这是由条令处理的。条令应该将WikiPageVersion转换为对象的ID属性(因为条令在flush()期间生成INSERT语句时有@ORM\ID
注释)
。此过程适用于除OneTONE关联之外的所有其他关联。现在我明白了,遗憾的是没有解决方案:(。