Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inheritance FactoryGirl用于父级和子级具有关联的具有继承的模型_Inheritance_Ruby On Rails 4_Associations_Factory Bot_Rspec Rails - Fatal编程技术网

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