You've got to write your mappedBy on the Entity's property, not the column.
Basically, the entities' properties must "talk to each other".
$comments
is mapped by $post
, $post
is inversed by $comments
:
class Posts
{
/**
* @OneToMany(targetEntity="CommentsBundle\Entities\Comments", mappedBy="post")
*/
protected $comments;
}
class Comments
{
/**
* @ORM\ManyToOne(targetEntity="ContentBundle\Entities\Posts", inversedBy="comments")
* @ORM\JoinColumn(name="post_id", referencedColumnName="id")
*/
protected $post;
}
Also, I wouldn't have defined $post_id
in your Comments
entity. Just $post
, and when you need to retrieve the post's id then:
public function getPost_id()
{
return $this->post->getId();
}
Things are cleaner this way.