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

include_root_in_json setting retrieval does not respect hierarchy

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.1
    • Affects Version/s: 7.0.6, 7.1.0
    • Component/s: Attributes
    • None

      ActiveModel has a knob called include_root_in_json (documented in https://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html) which controls the structure of the as_json method output. This knob is supported by Mongoid but its values are not being read correctly.

      Test case: https://github.com/p-mongo/tests/blob/master/mongoid-app/lib/tasks/test_4865.rake

      Output:

      
      Mongoid: false
      Foo: false
      foo: false
      Sub: false
      sub: false
      
      Mongoid -> true
      
      Mongoid: true
      Foo: false
      foo: true
      Sub: false
      sub: true
      
      Foo -> true
      
      Mongoid: false
      Foo: true
      foo: false
      Sub: true
      sub: false
      
      Sub -> true
      
      Mongoid: false
      Foo: false
      foo: false
      Sub: true
      sub: false
      
      

      The class level value is not influenced by the global Mongoid value, and the instance value is not influenced by the class level value.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: