基本は下記を見る。
以下の <<
を使った親子関係の子を挿入してsave!したところでnull例外。parent_children.parent_id
がnullと言う。
rb
child = FactoryGirl.create(:child)
parent.child << child
stage.save!
下記のように命じする事で回避。
rb
child = FactoryGirl.build(:child)
parent.parent_children.build(parent:parent, child: child)
stage.save!
本当の原因を探っていないがこういうことがあった記録を取っておく。