我已經得到了這些類中進行選擇:活動記錄3嵌套表
class Game < ActiveRecord::Base
has_many :offers
#table has an integer-column 'season'
end
class Broker < ActiveRecord::Base
has_many :offers
end
class Offer < ActiveRecord::Base
belongs_to :game
belongs_to :broker
end
,我想選擇從一個經紀人那裏比賽的賽季是2009年,例如,所有的優惠。 我試圖
Broker.first.offers.joins(:game).where(:game => {:season => 2009}).each do |o|
puts o.inspect
end
但是這給了我
`rescue in log': PGError: ERROR: missing FROM-clause entry for table "game" (ActiveRecord::StatementInvalid) LINE 1: ...games" ON "games"."id" = "offers"."game_id" WHERE "game"."se... : SELECT "offers".* FROM "offers" INNER JOIN "games" ON "games"."id" = "offers"."game_id" WHERE "game"."season" = 2009 AND ("offers".broker_id = 1)
我應該怎麼做這樣的選擇,或在哪裏可以找到更多這方面的信息?
謝謝,這是非常有益的! – user573335 2011-03-27 18:59:47
我愛你,我一直在尋找這個小問題好幾個小時。謝謝。 – jphenow 2012-01-22 22:07:17