Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4973

STI accepts_nested_attributes_for no longer working (throws "not allowed")

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 7.1.1, 7.0.8
    • Component/s: Attributes
    • Labels:
      None
    • Environment:
      production

      If you have a class with STI where the descendant declares a new attribute:

       

      class A
      
      ...
      
       
      
      class B < A
      
      field :secondary_description, type: String
      
       

      And  you have a has many

       

      class Something
      
      ...
      
      has_many :as
      
      accepts_nested_attributes_for :as
      
       

      And then you create a form, upon creation, if you do

       

      something = Something.new(allowed_params)
      

       

      You get an error:

       

       

      Attempted to set a value for 'secondary_description' which is not allowed on the model A

      {{}}

      This worked fine in Mongoid 6.0, it seems like the instantiation of the has_manys from params is not creating an in-memory object of type B, but instead, is creating an object of type A{{}}

       

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            kevin@mainstreetcomputing.com Kevin Chugh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: