私は2つのテーブルを持っています:
通貨とレート
currencies: id:int, code:string, name: string
rates: id:int, top_currency_id:int, bottom_currency_id:int, rate:float
そして、私はそれらのために2つのアクティブなレコードを持っています:
class Rate < ActiveRecord::Base
attr_accessible :bottom_currency, :rate, :top_currency, :top_currency_id
belongs_to :top_currency, :class_name => 'Currency', :foreign_key => 'top_currency_id'
belongs_to :bottom_currency, :class_name => 'Currency', :foreign_key => 'bottom_currency_id'
end
class Currency < ActiveRecord::Base
attr_accessible :code, :name
has_many :rates
end
問題は次のとおりです。次のコードを実行しようとすると: top_currency = Currency.find_by_id(1) @test = Rate.where(:top_currency=>top_currency)
次のエラーが表示されます:
Mysql2::Error: Unknown column 'rates.top_currency' in
'where clause': SELECT `rates`.* FROM `rates` WHERE `rates`.`top_currency` = 1
Rails の魔法が効かないのはなぜですか?
どうもありがとう。