Marek
Marek

Reputation: 147

How to use doctrine One-To-Many, Bidirectional?

I am making blog maker in symfony and doctrine

I am trying to connect, ID of row in blog posts with comments by blog_id value, but I getting this error

\Entity\BlogPosts.php

The association App\Entity\BlogPosts#comments refers to the owning side field App\Entity\Frontend\Blog\Fe_blog_comments#blogId which is not defined as association, but as field.

The association App\Entity\BlogPosts#comments refers to the owning side field App\Entity\Frontend\Blog\Fe_blog_comments#blogId which does not exist.

My actual code looks like this

\Entity\BlogPosts.php

class BlogPosts
{
    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Frontend\Blog\Fe_blog_comments", mappedBy="blogId")
     */
    private $comments;

    //...
}

\Entity\Frontend\Blog\Fe_blog_comments.php

class Fe_blog_comments
{
    //...

    /**
     * @ORM\Column(type="integer")
     * @ORM\ManyToOne(targetEntity="App\Entity\BlogPosts", inversedBy="comments")
     * @ORM\JoinColumn(name="blog_id", referencedColumnName="id")
     */
    private $blogId;

    //...
}

Upvotes: 0

Views: 75

Answers (1)

msphn
msphn

Reputation: 309

Remove @ORM\Column(type="integer"), the column should be managed by @ORM\JoinColumn(name="blog_id", referencedColumnName="id")

Upvotes: 1

Related Questions