Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2646

Column name `id` referenced for relation from EntityB towards EntityA does not exist.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.3.4
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      /**
       * @ORM\Entity()
       */
      class EntityA {
      
          /**
           * @ORM\Id
           * @ORM\Column(type="string", length=255)
           * @var string
           */
          protected $name;
      
          /**
           * @ORM\ManyToMany(targetEntity="EntityB", mappedBy="as")
           */
          protected $bs;
      }
      
      /**
       * @ORM\Entity()
       */
      class EntityB {
      
          /**
           * @ORM\Id
           * @ORM\Column(type="integer")
           * @var string
           */
          protected $id;
      
          /**
           * @ORM\ManyToMany(targetEntity="EntityA", inversedBy="bs")
           */
          protected $as;
      }
      

      Trying to generate the schema throws an exception:

      Column name `id` referenced for relation from EntityB towards EntityA does not exist.
      

      If I change the name of the @Id field in EntityA from $name to $id, everything works.

      I have tried adding @JoinColumn definition to EntityB like this:

          /**
           * @ORM\ManyToMany(targetEntity="EntityA", mappedBy="as")
           * @ORM\JoinTable(name="a_to_b", joinColumns={@ORM\JoinColumn(name="entitya_name", referencedColumnName="name")}
           * )
           */
          protected $bs;
      

      But that just changes the name of the field in the error message:

      Column name `name` referenced for relation from EntityB towards EntityA does not exist.
      

        Activity

        Hide
        Goran Juric added a comment -

        Finally found the issue, when I moved the definition of the JoinTable to EntityA it all worked as expected.

        Show
        Goran Juric added a comment - Finally found the issue, when I moved the definition of the JoinTable to EntityA it all worked as expected.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Goran Juric
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: