由於某些原因,當我運行下面的seed.rb文件時,'ratings'中的food_id字段未填充。有人可以幫我弄清楚爲什麼?Rails DB播種
種子文件包含以下行:
Food.create(:id => 1, :description => 'Stonyfield Farm Yomommy 4oz. Strawberry')
OverallRating.create(:score => 0, :count => 1, :food_id => 1)
規範食品和評級如下: 類OverallRating <評級 belongs_to的:食品 結束
class Food < ActiveRecord::Base
has_one :overall_rating
end
class Rating < ActiveRecord::Base
belongs_to :food
end
該評級遷移文件如下:
class CreateRatings < ActiveRecord::Migration
def self.up
create_table :ratings do |t|
t.integer :food_id
t.integer :count
t.decimal :score
t.string :type
t.timestamps
end
end
def self.down
drop_table :ratings
end
end
我有一種感覺,這與我在評分和總體評分中使用單表繼承有關。但不能肯定... – Tian 2010-07-08 01:48:11
貌似遷移代碼沒有被正確突出,可能需要編輯和修正壓痕真正的快速 – mportiz08 2010-07-08 01:49:23