由于某些原因,当我运行下面的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