Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:23:18+00:00 2026-06-17T16:23:18+00:00

I appear to be having a problem creating a simple One to Many relationship

  • 0

I appear to be having a problem creating a simple One to Many relationship between my blog and my blog_link_tag join table. I’m almost there however I keep on receiving the following mapping error from Doctrine and I’m wondering if anyone can point out where I’m going wrong?

The association Acme\BlogBundle\Entity\Blog#tags refers to the owning side field Acme\BlogBundle\Entity\BlogLinkTag#blog_id which does not exist.

Below is the table structure I’m using with unnecessary fields removed.

CREATE TABLE `blog` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `blog_link_tag` (
  `id` int(3) NOT NULL AUTO_INCREMENT,
  `blog_id` int(3) NOT NULL,
  `tag_id` int(3) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Blog.php

<?php

namespace Acme\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Blog
 *
 * @ORM\Table(name="blog")
 * @ORM\Entity(repositoryClass="Acme\BlogBundle\Entity\BlogRepository")
 * @ORM\HasLifecycleCallbacks
 */

class Blog {

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;


    /**
     * @ORM\OneToMany(targetEntity="BlogLinkTag", mappedBy="blog_id")
     */
    protected $tags;


    public function __construct() {
        $this->tags = new ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId() {
        return $this->id;
    }


    /**
     * Add tags
     *
     * @param \Acme\BlogBundle\Entity\BlogLinkTag $tags
     * @return Blog
     */
    public function addTag(\Acme\BlogBundle\Entity\BlogLinkTag $tags) {
        $this->tags[] = $tags;

        return $this;
    }

    /**
     * Remove tags
     *
     * @param \Acme\BlogBundle\Entity\BlogLinkTag $tags
     */
    public function removeTag(\Acme\BlogBundle\Entity\BlogLinkTag $tags) {
        $this->tags->removeElement($tags);
    }

    /**
     * Get tags
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getTags() {
        return $this->tags;
    }

    /**
     * Set tags
     *
     * @param integer $tags
     * @return Blog
     */
    public function setTags($tags) {
        $this->tags = $tags;
        return $this;
    }
}

BlogLinkTag.php

<?php

namespace Acme\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * BlogLinkTag
 *
 * @ORM\Table(name="blog_link_tag")
 * @ORM\Entity
*/
class BlogLinkTag
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var integer
     * @ORM\Column(name="blog_id", type="integer", nullable=false)
     * @ORM\ManyToOne(targetEntity="Blog", inversedBy="blog")
     * @ORM\JoinColumn(name="blog_id", referencedColumnName="blog_id")
     */
    private $blogId;

    /**
     * @var integer
     *
     * @ORM\Column(name="tag_id", type="integer", nullable=false)
     */
    private $tagId;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId() {
        return $this->id;
    }


    /**
     * Set blogId
     *
     * @param integer $blogId
     * @return BlogLinkTag
     */
    public function setBlogId($blogId) {
        $this->blogId = $blogId;

        return $this;
    }

    /**
     * Get blogId
     *
     * @return integer 
     */
    public function getBlogId() {
        return $this->blogId;
    }

    /**
     * Set tagId
     *
     * @param integer $tagId
     * @return BlogLinkTag
     */
    public function setTagId($tagId) {
        $this->tagId = $tagId;
        return $this;
    }

    /**
     * Get tagId
     *
     * @return integer 
     */
    public function getTagId() {
        return $this->tagId;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:23:20+00:00Added an answer on June 17, 2026 at 4:23 pm

    Take a look at the official documentation about association mapping here.

    Try this :

    In BlogLinkTag

        /**
         * @var integer
         * @ORM\ManyToOne(targetEntity="Blog", inversedBy="tags") //put the name of the variable in the other entity here
         * @ORM\JoinColumn(name="blog_id", referencedColumnName="id") //reference of the column targetted here
         */
        private $blog;
    

    In Blog :

        /**
         * @ORM\OneToMany(targetEntity="BlogLinkTag", mappedBy="blog") //put the name of the variable in the other entity here
         */
        protected $tags;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem where my javascript plugins appear to be conflicting, but
I'm having difficulty with a Flex app I'm creating. I believe the problem is
I am creating an image hover effect but I am having problem with it.
I am having a problem with a table and showing another view when the
I have a little problem that i'm creating a simple search application which have
I am creating a simple math program with 6 different problem types. I want
I'm fiddling w/ dojo (1.4) and am having a problem programmatically creating floating panes
I am having problems getting segments of small lengths to appear in my plot.
I have recently taken the ABS4.0 dive. However, I appear to be having an
I'm having trouble trying to get a linebreak included in a Stringbuilder to appear

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.