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

Serialization with embedded relations is inconsistent

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

      If I add an embedded relation before saving a document, the relation is serialized (without the :includes option):

      person = Person.new
      person.write_attributes(:title => "President")
      person.addresses.build(:street => "Kudamm")
      person.save
      person.serializable_hash
      => {'title' => 'President', 'addresses' => [

      {'street' => 'Kudamm'], ...}

      But if the relation is added after saving a document, the relation is not serialized:

      person = Person.new
      person.write_attributes(:title => "President")
      person.save
      person.addresses.build(:street => "Kudamm")
      person.save
      person.serializable_hash
      =>

      {'title' => 'President', ...}

      If I pass :includes => ['addresses'] to the serialize_hash method, it works in both situations. What is the intended behavior when :includes is not specified?

      The attached specs demonstrate the problem. 2 of the 4 added specs fail.

      (I'm using mongoid 2.4.3)

            Assignee:
            Unassigned Unassigned
            Reporter:
            blt04 Brandon Turner
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: