【发布时间】:2019-07-17 19:48:25
【问题描述】:
当我进行迁移时,我收到以下错误 "ActiveRecord::RecordInvalid: 验证失败:狩猎动物必须存在"
我不确定我会在哪里声明“狩猎动物”。
class Picture < ApplicationRecord
belongs_to :camera_model
has_one :animals, :as =>:HuntingAnimals
end
class User < ApplicationRecord
has_one :animals, :as =>:HuntingAnimals
end
class Animal < ApplicationRecord
belongs_to :HuntingAnimals, :polymorphic => true
end
class CreateAnimals < ActiveRecord::Migration[5.2]
def change
create_table :animals do |t|
t.references :HuntingAnimals, polymorphic: true
end
end
end
【问题讨论】:
标签: ruby-on-rails-3 polymorphic-associations