Inheritance FactoryGirl用于父级和子级具有关联的具有继承的模型
我有一个典型的继承模式,但是父对象与另一个模型有关联,子对象也与其他模型有关联Inheritance FactoryGirl用于父级和子级具有关联的具有继承的模型,inheritance,ruby-on-rails-4,associations,factory-bot,rspec-rails,Inheritance,Ruby On Rails 4,Associations,Factory Bot,Rspec Rails,我有一个典型的继承模式,但是父对象与另一个模型有关联,子对象也与其他模型有关联 class MyBase < ActiveRecord::Base belongs_to :game, inverse_of: :my_base validates :game, presence: true end class Child < MyBase self.table_name = 'children' belongs_to :user, inverse_of: :child
class MyBase < ActiveRecord::Base
belongs_to :game, inverse_of: :my_base
validates :game, presence: true
end
class Child < MyBase
self.table_name = 'children'
belongs_to :user, inverse_of: :child
validates :user, presence: true
end
这使我在起毛时的工厂无效:
child-无法写入未知属性“user\u id”(ActiveModel::MissingAttributeError)
我需要如何设置我的工厂以创建这两个关联
PS:这是一种多表继承情况。通过使用子类作为“类”名称使其正常工作:
这可能是因为factory girl linter正在使用活动记录表定义进行lint,并且没有考虑应用程序级别上的连接?
factory :child, class: MyBase, parent: :my_base do
association :user, strategy: :build
end
FactoryGirl.define do
factory :child, class: Child, parent: :my_base do
association :owner, factory: :user, strategy: :build
end
end