0
我正在設置一個應用程序來發布想要/可用/易貨的物品。我有兩個主要的類,Post和Item。設置具有多個has_one關係的外鍵
每個帖子都包含offered_item,wanted_item或兩者。這裏是我目前的定義:
class Post < ActiveRecord::Base
has_one :wanted_item, :class_name => 'Item', :dependent => :destroy
has_one :offered_item, :class_name => 'Item', :dependent => :destroy
has_one :location, :dependent => :destroy
end
和
class Item < ActiveRecord::Base
belongs_to :post
attr_accessible :title, :description
end
關於我的問題:如何組織的外鍵的項目表,這樣我可以知道哪些職位(以及它是否是一個wanted_item或offered_item)?這是在遷移文件還是在模型中完成的?
因爲它目前是,當我嘗試一個查詢,如:
我得到如下:
的SQLite3 ::的SQLException:沒有這樣的列:items.post_id:SELECT 「 「FROM」items「WHERE」items「。」post_id「= 1 LIMIT 1
這很好,謝謝! –