如何将此SQL查询转换为DQL? [英] How to translate this SQL Query to DQL?

查看:160
本文介绍了如何将此SQL查询转换为DQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试将此SQL查询转换为DQL时遇到了很多困难(我正在使用Symfony2)。




SELECT d。* FROM Document d JOIN DocumentType dt ON dt.id = d.document_type_id WHERE(d.dateFinal - INTERVAL dt.renewal SECOND)> NOW();
/ p>

非常感谢!

解决方案


  • 而不是数据库字段,您需要使用 Document DocumentType 类的字段。


  • join 是通过命名关联字段(类似 d.documenttype


  • 对于那些MySQL日期函数:至少据我所知,你需要写自定义DQL函数。在该链接后面有一个 INTERVAL 函数的示例。这可能是您要执行本机SQL查询的一个点。




  SELECT d 
FROM MyProject\Model\Document d
JOIN d.documenttype
WHERE [...您自己的DQL函数在这里...]


I have a lot of difficulties in trying to translate this SQL query to a DQL one (I am using Symfony2).

SELECT d.* FROM Document d JOIN DocumentType dt ON dt.id = d.document_type_id WHERE (d.dateFinal - INTERVAL dt.renewal SECOND) > NOW();"

Thanks a lot !

解决方案

  • Instead of database fields, you need to use the fields of you Document and DocumentType classes.

  • The join is done by naming the association field of your document (something like d.documenttype)

  • For those MySQL date functions: At least as far as I know, you would need to write custom DQL functions. Behind that link there is an example of an INTERVAL function. This might be the point where you want to execute the native SQL query instead.

SELECT d 
FROM MyProject\Model\Document d
    JOIN d.documenttype
WHERE [...your own DQL functions here...]

这篇关于如何将此SQL查询转换为DQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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