doctrine2 dql 通过实体内序列化对象的属性进行查询

发布于 2024-09-25 07:10:52 字数 213 浏览 1 评论 0原文

我有一个带有“对象”类型列的实体。我希望能够通过该对象的属性(例如 id)检索实体。例如,查询看起来像这样:

$em->createQuery('SELECT e FROM Entity_Class e SOME_MAGIC e.object o WHERE o.id = ?1');

问题是,dql 中有 *SOME_MAGIC* 吗?

I have an entity with an 'object' type column. I want to be able to retreive the entity by a property (say id) of that object. For example, the query would look something like this:

$em->createQuery('SELECT e FROM Entity_Class e SOME_MAGIC e.object o WHERE o.id = ?1');

The question is, is there *SOME_MAGIC* in dql?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执妄 2024-10-02 07:10:52

使用serialize() 将对象类型列序列化为CLOB 字段是不可能的。无法查询它的子属性。

This is not possible an object type column is serialized into a CLOB field using serialize(). There is no way to query subproperties of it.

断肠人 2024-10-02 07:10:52

一种可能但不是最佳的解决方案是使用类似 expr:

 $qb->add($qb->expr()->like("e.column", $qb->expr()->literal("%text_to_search%")));

因为在某些 RDBMS 中的原则 2 中,对象以长文本类型持久化,而不是 CLOB 或 BLOB。

A possible solution but not the optimal one is to use a like expr:

 $qb->add($qb->expr()->like("e.column", $qb->expr()->literal("%text_to_search%")));

Because in doctrine 2 in some RDBMS, the object are persist in longtext type and not CLOB or BLOB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文