mercredi 17 juillet 2019

validation failed in polymorphic association

When I do a migration I get the following error "ActiveRecord::RecordInvalid: Validation failed: Huntinganimals must exist"

I'm not sure where I would declare "huntinganimals".

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

Aucun commentaire:

Enregistrer un commentaire