如何使用 PHP 属性声明 joinColumns/复合键。未能找到正确的方法,并且没有记录 ( https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/reference/attributes-reference.html )
实体
评论.php
#[ORM\Entity(repositoryClass: CommentRepository::class)]
class Comment
{
#[ORM\Id]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\ManyToOne(targetEntity: PullRequest::class, inversedBy: 'comments')]
#[ORM\JoinColumn(name: 'pull_request_id', referencedColumnName: 'id')]
#[ORM\JoinColumn(name: 'repo_id', referencedColumnName: 'repo_id')]
private $pullRequest;
}
PullRequest.php
#[ORM\Entity(repositoryClass: PullRequestRepository::class)]
class PullRequest
{
#[ORM\Id]
#[ORM\Column(type: 'integer', unique: false)]
private $id;
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: Repo::class, inversedBy: 'pullRequests')]
#[ORM\JoinColumn(nullable: false)]
private $repo;
#[ORM\OneToMany(mappedBy: 'pullRequest', targetEntity: Comment::class, orphanRemoval: true)]
private $comments;
}
最佳答案
根据https://github.com/greg0ire/doctrine-orm/commit/18366db5789b03e1d8a34933fbbff97a768a9cfe不再需要“JoinColumns”属性,多个“JoinColumn”属性就足够了。
关于php - 具有 php 属性的 JoinColumns/复合键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71798641/