Objects are built twice when relation is specified in the constructor

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 7.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      OK,

      @chart= FactoryGirl.create(:ias_chart)
      @time = DateTime.now
      @ias_accounts = [411, 512]
      @ias_accounts.each do |number|
        (-1..1).each do |offset|
            @chart.ias_accounts << IasAccount.new(:number => number, :time => @time+ offset.days, :ias_chart => @chart)
          end
      end
      [411, 512]
      
      >> @chart.ias_accounts.size
      12
      

      while

      @chart= FactoryGirl.create(:ias_chart)
      @time = DateTime.now
      @ias_accounts = [411, 512]
      @ias_accounts.each do |number|
        (-1..1).each do |offset|
            @chart.ias_accounts << IasAccount.new(:number => number, :time => @time+ offset.days)
          end
      end
      [411, 512]
      
      >> @chart.ias_accounts.size
      6
      

      The only difference between the two is that :ias_chart is specified in the IasAccount constructor in the first case and not in the second one.

      Is that a desired behavior?!

            Assignee:
            Emily Stolfo (Inactive)
            Reporter:
            Olivier Milla
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: