我正在尝试做这样的事情,但我不确定你是否可以通过内部连接来做到这一点:
SELECT "scores".*
FROM "scores"
INNER JOIN "games" ON "games"."id" = "scores"."games_id"
WHERE
"games"."date" >= '2013-02-11 19:30:11.799227'
AND "scores".value > 350;
谢谢您的帮助。此外,如果您知道如何编写 ActiveRecord / arel 语句,那么查询也会有所帮助。
我的模型如下所示:
class Score < ActiveRecord::Base
belongs_to :game
delegates :date, to: game
end
class Game < ActiveRecord::Base
has_many :scores, dependent: :destroy
end