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

Invalid length for an unsaved embeds_many

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:
      None

      Description

      I ran into a strange bug. I have an object that embeds several instances of another. Until I persist the parent, the count of the embedded objects is 0. Here's the code:

      Parent:
      {{ embeds_many :segments, cascade_callbacks: true}}
      Segment:
      {{ embedded_in :parent}}

      1.9.3p125 :061 > q = Parent.new
       => #<Parent _id: 51b91f26679d6b943f00001b, ...> 
      1.9.3p125 :062 > q.segments = [Segment.new, Segment.new]
       => [#<Segment _id: 51b91f2b679d6b943f00001c, >, #<Segment _id: 51b91f2b679d6b943f00001d, >] 
      1.9.3p125 :064 > q.segments.count
       => 0 
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            emirkin Eugene Mirkin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: