ActiveModel#serializable_hash skips autobuild associations

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Won't Fix
    • Priority: Major - P3
    • 6.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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
              Reporter:
              rwz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: