doujiao2443 2012-02-03 03:23
浏览 42
已采纳

如何在Doctrine 2中为1:1关系指定多个连接条件

Documentation states:

class Cart
{
    // ...

    /**
     * @OneToOne(targetEntity="Customer", inversedBy="cart")
     * @JoinColumn(name="customer_id", referencedColumnName="id")
     */
    private $customer;

    // ...
}

This annotation represents such sql:

JOIN Customer c ON c.id = cart.customer_id

And the issue is that I need to add additional comparison there, like:

JOIN Customer c ON c.id = cart.customer_id AND c.anotherField = <constant>

Any solutions for that?

UPD:

the real additional condition I need for now is <const> BETWEEN c.f1 AND c.f2

  • 写回答

2条回答 默认 最新

  • douqi1212 2012-02-08 13:52
    关注

    you can use the WITH keyword to specify additional join conditions, as you can see in some of the examples.

    i think this should get you going:

    SELECT l, c FROM location
    INNER JOIN Customer c
    WITH CURRENT_TIMESTAMP() BETWEEN c.f1 AND c.f2
    WHERE CURRENT_TIMESTAMP() BETWEEN l.f1 AND l.f2
    

    i removed the ON clause because i think there's no need to explicitly specify the join's ON fields unless they are not the "standard" ones (id of each entity)

    also notice the call to CURRENT_TIMESTAMP() which translates into MySQL's NOW(). check out a list of other pretty useful aggregate functions and expresions here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal