Doctrine 2 - One-To-Many with multiple Entities

2019-05-30 03:35发布

I have a few Entities that I would like to be able to map Comments to (Profiles, Posts, Images, Videos - things like that).

Each of these Entities has a column that contains a guid, and what I would like to do is have the Comment table hold the guid to the item to which it belongs. What I can't figure out is how to configure Doctrine to handle this kind of thing so that the joins work. The solution I think might work is to use NativeSql (although I am not sure that will work either), but would rather not have to do that if at all possible.

I don't imagine I am the first one to encounter this problem, so I hope someone out there can help!

Thanks.

1条回答
再贱就再见
2楼-- · 2019-05-30 04:07

I think you can use inheritance mapping for that, can't you? You will need something like CommentableEntity, from which Profiles, Posts, Images, Videos are inherited.

It adds some overhead and you need to check if it's ok for your task.

查看更多
登录 后发表回答