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

JSON Serialization for Embedded Relations

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.8
    • Affects Version/s: None
    • Component/s: None
    • None

      Hi,

      I'm noticing a bug with the following when JSON serializing Embedded Relations:

      class Foo
      include Mongoid::Document

      embeds_many :bars
      end

      class Bar
      include Mongoid::Document

      embedded_in :foo
      belongs_to :baz
      end

      class Baz
      include Mongoid::Document
      end

      doesnt_include_full_baz_object = Foo.new.tap do |f|
      f.bars << Bar.new(baz: Baz.create)
      f.save
      end.to_json include: {
      bars: {
      baz: {}
      }
      }

      1. This includes just the baz_id but not the full baz document itself
        doesnt_include_full_baz_object

      I can currently work around this but I would've expected the JSON serializer to return a full Baz document.

            Assignee:
            Unassigned Unassigned
            Reporter:
            tazsingh Tasveer Singh
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: