0
与这个关联一起挣扎,我有两个模型:图和市场,您可以在其中与其他人交易您的玩具图。在一个有两个外键的模型与另一个模型之间创建一个关联
Figure class
figure_id:integer
name :string
image_url:string
Market class
market_id:integer
figure_you_want_to_trade_id :integer #this should be associated with the figure_id
figure_you_want_from_someone_else_id:integer #this should be associated with the figure_id
我该如何去做这种关联?
我在想:
market.rb
has_many :figure_to_trade, :class_name => Figure, :foreign_key => figure_id
has_many :figure_you_want, :class_name => Figure, :foreign_key => figure_id
figure.rb
belongs_to :figure_you_want_to_trade, :class_name => Market
belongs_to :figure_you_want_from_someone_else, :class_name => Market
这是我收到的错误,当我试图输出这个:<%= market.figure_to_trade%>
的SQLite3 ::的SQLException:没有这样的柱:figures.figure_id:SELECT “人物” * FROM “人物” WHERE “人物”, “figure_id”= 1