【发布时间】:2023-01-05 21:28:50
【问题描述】:
如何使用 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;
}
【问题讨论】:
标签: php doctrine-orm doctrine