用Doctrine2存储动态字段 [英] Storing dynamic fields with Doctrine2

查看:93
本文介绍了用Doctrine2存储动态字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,我们正在寻求使用doctrine2,但是,我们想提供一个功能,但是对于它的工作原理完全混淆。

in our app, we are looking to use doctrine2, however, there is one feature we want to offer but am completely confused as to how it would work.

我们希望我们的客户能够为自己的标准对象定义自定义字段。因此,这些字段将被即时制作,而不是由doctrine知道和映射的对象定义的一部分。

we want our customers to be able to define custom fields to our standard objects. so, these fields would be made on-the-fly, and not part of the object definition that is known and mapped by doctrine.

我们的第一个想法是使用nosql (mongodb或者amazon dynamodb)来存储这些数据,但是由于我们想要使用原则来处理我们的核心对象,所以我们希望在理论的范围内实现这一点,而无需超越它来存储这些数据。

our first thought was to use nosql (mongodb or amazon dynamodb) to store some of this data, but since we want to use doctrine to handle our core objects, we would like to stay within the realm of doctrine to achieve this without have to extend beyond it to store this data.

我的想法中有一件事是使用doctrine的能力来对复杂对象进行序列化/取消排序,只需将自定义字段名称和它们的值作为对象的额外属性但是,这不允许我们有一个功能可以搜索这些字段,如果我们想要允许...

one thing on my mind was using doctrine's ability to serialize/unserialize complex objects and just have like a hash of custom field names and their values as an extra property in the object, however, this would not allow us to have a feature that would search these fields if we ever wanted to allow that...

任何人试图用doctrine2或任何orm变体?

anyone ever attempted to do this with doctrine2 or any orm variant?

推荐答案

你可以考虑使用Doctrine ODM,这是Doctrine 2,但是NoSQL - 我相信他们支持最少的MongoDB。

You could consider using Doctrine ODM, which is Doctrine 2 but for NoSQL - I believe they support at least MongoDB.

另一种方法是使用序列化。您可能不应该担心搜索太多 - 我建议使用单独的全文搜索引擎(Solr,ElasticSearch或其他),因为它们为搜索和SQL全文搜索提供了更多的多功能性和性能。

Another approach would be to use serialization as you said. You probably shouldn't worry about search too much - I would recommend to use a separate fulltext search engine (Solr, ElasticSearch, or other) as they provide much more versatility and performance for search vs SQL fulltext search.

第三,您可以使用Doctrine与NoSQL一起使用。在这种情况下,您可能应该将查询抽象为服务类等,以便您可以使用Doctrine来查询SQL数据库中的数据,另一些可以查询剩余的数据。

Third, you could use Doctrine alongside with NoSQL. In this case, you probably should abstract your querying into a service class or such, so that you can use Doctrine to query for the data from your SQL DB, and some other to query the remaining data.

最后,您可以考虑使用键值表。一列代表键,另一列代表值。

Finally, you could consider using a key-value table. One column represents the key, another the value.

这篇关于用Doctrine2存储动态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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