我有一个非常复杂的SQL查询,我想将其转换为Propel,但我不确定最佳方法。
我需要的查询如下所示:
SELECT id_loan
FROM loan loanA
JOIN loan_funding on fk_loan = loanA.id_loan
JOIN `user` userA on loan_funding.fk_user = userA.id_user
WHERE
userA.`acc_internal_account_id` is not null
AND loanA.`state` = 'payment_origination'
AND loanA.id_loan IN (
SELECT id_loan from loan loanB
JOIN loan_funding on fk_loan = id_loan
JOIN `user` userB on loan_funding.fk_user = userB.id_user
WHERE
userB.`acc_internal_account_id` is null
AND loanB.`state` = 'payment_origination'
GROUP BY loanB.id_loan
)
GROUP BY loanA.id_loan
LIMIT 1;
我想要的是完全基于生成查询方法的东西,但我不知道如何做到这一点。
性能不是问题,但目前尚不清楚这些查询的调用位置和方式。但是,在我们需要使用getter和setter时返回一个对象很重要。
我找到了这个网站:http://propelorm.org/blog/2011/02/02/how-can-i-write-this-query-using-an-orm-.html看起来很酷且很有帮助,但是,我不确定哪个选项最合适。
我不期待一个完整的解决方案,但也许有些想法如何缩小问题...
令我困惑的是特别是它在转到用户表之前比较id_loan和fk_loan的部分。如何用推进来表示这种关系?在多个查询中分割整个事物可能会更好吗?
任何提示都赞赏!