How to specify a polymorphic association in a fixture

I have this device:

resource: name: my resource owner: user_1 (User) 

A resource is defined as follows:

 class Resource < ActiveRecord::Base belongs_to :owner, :polymorphic => true 

The user is defined as follows:

 class User < ActiveRecord::Base has_many :resources, :as => :owner 

When I run the test, I get an error that the owner of the column is not defined in the table. What am I doing wrong?

+6
source share
1 answer

The device must have owner_id and owner_type. For example: owner_id as 1 and owner_type as "User"

+2
source

Source: https://habr.com/ru/post/894603/


All Articles