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

double the number of objects from has_many association when enumerating

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

      Using 2.4.4, #each loops through my has_many association objects twice:

      class Parent

      has_many :items, :class_name=>"Something::Item", as: :itemizable, dependent: :nullify

      ...

      class Something::Item

      belongs_to :itemizable, polymorphic: true

      ...

      In parent...

      times_run = 0
      p "items size #

      {items.size}

      "
      items.each do |pl|
      times_run += 1
      p "item #

      {pl}

      "
      end
      p "times run #

      {times_run}

      "

      result...

      "items size 3"
      "item #<Something::Item:0x2dbd8e4>"
      "item #<Something::Item:0x2db0e00>"
      "item #<Something::Item:0x2da5618>"
      "item #<Something::Item:0x2dbd8e4>"
      "item #<Something::Item:0x2db0e00>"
      "item #<Something::Item:0x2da5618>"
      "times run 6"

      thx, g

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

              Created:
              Updated:
              Resolved: