假设我有以下型号:
User
ident Text
password Text Maybe
UniqueUser ident
deriving Typeable
Payment
timestamp UTCTime
from UserId
to UserId
receiptId ReceiptId
ReceiptUser
userId UserId
receiptId ReceiptId
Receipt
owner UserId
money Int
我想执行这样的查询:
SELECT ReceiptUser.UserId, Receipt.ReceiptOwner, Receipt.Id, Receipt.Price
FROM ReceiptUser, Receipt, Payment
WHERE ReceiptUser.ReceiptId == Receipt.Id
AND NOT (Payment.ReceiptId == Receipt.Id AND Payment.From == ReceiptUser.UserId AND Payment.To == Receipt.Owner)
应该是找到所有还没有给其他用户付款的用户,加上相应的收据信息。
我怎么能用 yesod 持久表达这一点?在我看来,persistent 只为一个表上的简单查询提供了一个接口。