我将如何在 RoR 中形成以下 SQL 查询?
在 SQL 中,我会做这样的事情:
SELECT * FROM Gifts G
JOIN Payments P ON P.id = G.payment_id
JOIN Users U ON U.id = P.user_id
WHERE G.type = 0
我有三个模型——用户、付款和礼物。
架构如下所示:
Users has many Payments
Payments has many Gifts
Users
# Table name: users
# id :integer not null, primary key
# name :string
Payments
# Table name: payments
#
# id :integer not null, primary key
# user_id :integer
# status :integer
Gifts
# Table name: gifts
#
# id :integer not null, primary key
# payment_id :integer
# name :string
# type :integer