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 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题