어떤 이유에서 아래의 seed.rb 파일을 실행할 때 '등급'의 food_id 필드가 채워지지 않습니다. 왜 누군가가 나를 알아낼 수 있습니까? 음식과 평가에레일 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
은 마이그레이션 코드가 정확하게 강조 표시되지 않는 것처럼 보이며, 들여 쓰기를 빠르게 수정하고 수정하려고 할 수 있습니다. – mportiz08