Match.where(approval: {summoner_id: 18})
Match Load (0.6ms) SELECT "matches".* FROM "matches" WHERE "approval"."summoner_id" = ? [["summoner_id", 18]]
SQLite3::SQLException: no such column: approval.summoner_id: SELECT "matches".* FROM "matches" WHERE "approval"."summoner_id" = ?
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: approval.summoner_id: SELECT "matches".* FROM "matches" WHERE "approval"."summoner_id" = ?
但如果我这样做
Approval.first.summoner_id
Approval Load (0.2ms) SELECT "approvals".* FROM "approvals" ORDER BY "approvals"."id" ASC LIMIT 1
#=> 18
出现了。
我正在尝试找到所有匹配,其中“匹配”的批准具有特定的召唤者ID。
如何搜索?
class Match < ActiveRecord::Base
belongs_to :approval
end
答案 0 :(得分:3)
您正在尝试引用approval
表中的列:
:approval => { summoner_id: 18 }
但是你犯了两个错误:
approvals
,而不是approval
。approval
或approvals
表。我想你的意思是说:
Match.joins(:approvals).where(:approvals => {summoner_id: 18})