什麼值這個inversedBy
註釋還有mappedBy
註釋裏面去? 什麼是targetEntity和referencedColumnName?(教義)的mappedBy和inversedBy和targetEntity註釋
這是我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
。 這個評論字符串究竟是指什麼? 我不知道評論意味着什麼。這是映射到一個表,或頂部的類的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,但它是非常難以理解。
這裏的任何細節都會很棒。
任何幫助將是巨大的。