2
votes

I know that the model shoudn't be like that but I have to do with that. I've 3 entities with columns:

  • category
    • id (@id)
    • categoryId
    • name
    • ...
  • product
    • id (@id)
    • categoryid
    • ...
  • owner
    • id (@id)
    • name
    • ...

I have done a manytomany association between category and owner (with a join table). I use the two columns id to join with the join table. (this works)

Now I'd like to do a OneToMany relationship between Category and Product. But the onyly way to link them is categoryId.

It doesn't work when Category.categoryId is not a primary key : The referenced column name 'categoryId' has to be a primary key column on the target entity class 'Catgeory'.

And if I put Category.categoryId as primary key (so 2 primary key with id), I've an issue with the manytomany relationship: The join columns of the many-to-many table 'JOINTABLE' have to contain to ALL identifier columns of the source entity 'Category', however 'categoryId' are missing.

How can I do?

Annotations on Category: For product:

@ORM\OneToMany(targetEntity="Product", mappedBy="category")

For owner:

@ORM\ManyToMany(targetEntity="Owner") @ORM\JoinTable(name="JOINTABLE", ... )

PS: I am not allowed to edit tables

1

1 Answers

0
votes

Looks like there is no solution for this one. I have the same issue and can't find any workaround.

See http://www.doctrine-project.org/jira/browse/DDC-1114. It was closed as it is an invalid usage.