我有实体开发人员和评论和关系很多评论给一个开发人员。当我看到开发人员的所有评论和编辑时,我需要表格 - 在数据库中添加,删除。这个问题有哪些解决方案
实体评论:
class Comments
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Developer", inversedBy="comments")
* @ORM\JoinColumn(name="talent_id", nullable = true, referencedColumnName="id")
* */
protected $talent;
/**
* @var string
*
* @ORM\Column(name="added_by", type="string", length=10, nullable=true)
*/
private $added_by;
/**
* @var string
*
* @ORM\Column(name="comment", type="string", length=10, nullable=true)
*/
private $comment;
实体开发者:
class Developer extends CustomUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/////
/**
* @ORM\OneToMany(targetEntity="Comments", mappedBy="talent", cascade={"persist", "remove"})
*/
protected $comments;
也许需要表格形式,但如何做到这一点?
答案 0 :(得分:0)
您正在寻找字段类型collection。
答案 1 :(得分:0)
class Comments
{
....
/**
*
*@ORM\ManyToOne(targetEntity="Developer", inversedBy="developer_to_comments")
* @ORM\JoinColumn(name="developer_to_comments_id", referencedColumnName="id", nullable=false)
*
*/
private $comments_to_developer;
...
}
和班级开发人员
class Developer extends CustomUser
{
....
/**
*
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="Comments", mappedBy="comments_to_developer", cascade={"remove"})
*/
private $developer_to_comments;
public function __construct()
{
$this->developer_to_comments = new ArrayCollection();
}
....
}
不要忘记use Doctrine\Common\Collections\ArrayCollection