0

I have a "Post" entity and I want users to vote for those posts. Votes by authenticated and anonymous users are being stored in separate DB tables, so there are two separate "VoteAnonymous" and "VoteAuthenticated" entities which implement the same interface.

Now I've got problem with defining a reference in a "Post" entity and its "targetEntity" option. I wonder if there is any way Doctrine2 could pick one of the polymorphic classes as its field's target entity.

Thanks for any help.

P.S. I'm not able to redesign the DB, there's a ton of legacy code that lies upon this data structure.

artshpakov
  • 214
  • 1
  • 11
  • Oh, well, I guess I just have to make the relation unidirectional and use good old PHP where I have to. – artshpakov Jul 29 '11 at 15:33
  • 1
    I guess this might be helpful: http://stackoverflow.com/questions/6634357/doctrine-orm-conditional-association/6634436#6634436 – Crozin Jul 30 '11 at 17:24
  • Sorry, took some time for me to see a point in your comment :) I somehow overlooked the @MappedSuperclass annotation. Would you post an answer so I cound accept it? – artshpakov Sep 13 '11 at 14:36

1 Answers1

0

Doctrine supports inheritance, so you should create two different entities that share a common parrent, say AbstractVote, which defines all properties.

See this answer - it contains an example of such structure.

Community
  • 1
  • 1
Crozin
  • 43,890
  • 13
  • 88
  • 135