【发布时间】:2023-03-29 14:14:01
【问题描述】:
inversedBy 注释和mappedBy 注释中包含哪些值? 还有什么是 targetEntity 和 referencedColumnName?
这是我的comment entity 的示例。如您所见,在我的教程中,它说在inversedBy 属性中写入字符串comments,在targetREntity 属性中写入\Application\Entity\Post。
/**
* This class represents a comment related to a blog post.
* @ORM\Entity
* @ORM\Table(name="comment")
*/
class Comment
{
/**
* @ORM\ManyToOne(targetEntity="\Application\Entity\Post", inversedBy="comments")
* @ORM\JoinColumn(name="post_id", referencedColumnName="id")
*/
protected $post;
}
对于这个,它说comments。 这个 cmets 字符串到底指的是什么?
我不知道 cmets 是什么意思。这是到表的映射,还是顶部类的 ORM 名称,还是其他什么。
还有,
以下是使用mappedBy 的示例:
/**
* @ORM\Entity
* @ORM\Table(name="post")
*/
class Post
{
// Post status constants.
const STATUS_DRAFT = 1; // Draft.
const STATUS_PUBLISHED = 2; // Published.
/**
* @ORM\OneToMany(targetEntity="\Application\Entity\Comment", mappedBy="post")
* @ORM\JoinColumn(name="id", referencedColumnName="post_id")
*/
protected $comments;
我开始阅读有关owning sides and inverse sides click here 的内容,但非常难以理解。
这里的任何细节都会很棒。
任何帮助都会很棒。
【问题讨论】:
标签: php zend-framework doctrine-orm zend-framework2 doctrine