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

ActiveModel#serializable_hash skips autobuild associations

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      model MyModel
        include Mongoid::Document
        embeds_one :foo, autobuild: true
      end
      
      model = MyModel.new
      model.as_json.include?(:foo) # => false
      model.foo # <#Foo:...>
      model.as_json.include?(:foo) # => true
      

      One would expect embeded thing always to be included in serialized hash. It could be fixed by eagerly loading autobuild embeds before serializing. Something like this:

      class Model
        def serializable_hash(*)
          eager_load_all_autobuilds
          super
        end
      end
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            rwz rwz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: