I have a class A
class A
include Mongoid::Document
has_many :bs
accepts_nested_attributes_for :bs
and a class B
class B
include Mongoid::Document
belongs_to :a
and a class C that inherits from B
class C < B
field :new_field, type: String
This worked fine with Mongoid 6. With Mongoid 7, on a form with fields_for, upon submit, I now get:
Attempted to set a value for 'new_field' which is not allowed on the model B
Note, this is NOT the mongoid polymorphism supported in 7.0 (I believe) b/c that is not talking about single table inheritance (STI), rather, it supports multiple tables belonging to a single class / table as the same symbol. This is not that. And I've tried using as and polymorphic:true.
Any ideas how to fix this?
Thanks, Kevin
Turns you for Mongoid 7.0 or Rails 5.2 (not sure which change broke this) you have to set the type in the form for STI, I did this by a hidden field:
This allows you to set descendant-only attributes.