Skip to content

Loading…

DDC-2646: Column name `id` referenced for relation from EntityB towards EntityA does not exist. #3381

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user gog:

/****
 * @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 nameid` 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.
@doctrinebot

Comment created by gog:

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

@doctrinebot

Issue was closed with resolution "Invalid"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.