主义2 - 多对多个实体的一对多 [英] Doctrine 2 - One-To-Many with multiple Entities

查看:130
本文介绍了主义2 - 多对多个实体的一对多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个实体可以将评论映射到(个人资料,帖子,图片,视频等)。

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

这些实体中的每一个都有一个包含guid的列,我想做的是将Comment表保存在其所属项目的guid。我不能弄清楚的是如何配置原则来处理这种事情,以使联接工作。我认为可能工作的解决方案是使用NativeSql(虽然我不知道这也可以工作),但是如果可能的话,宁可不用这样做。

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!

谢谢。

推荐答案

我想你可以使用继承映射,是不是?您将需要像CommentableEntity这样的东西,从中可以继承个人档案,帖子,图片,视频。

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.

这篇关于主义2 - 多对多个实体的一对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆