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

embeds_many - change tracking

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

      
      # The models
      
      class VProduct
        include Mongoid::Document
        include Mongoid::Timestamps
        include Tire::Model::Search
        include Tire::Model::Callbacks
      
        field :name                   # name -        Bezeichnung
      
        belongs_to :v_group
        embeds_many :p_images
      
        #elastic search
        index_name 'v-products'
        def to_indexed_json
          self.to_json
        end
      end
      
      class SubCalculation
        include Mongoid::Document
        # Timestamps sind im Objekt Berechnung
      
        ###############    RELATIONS   #################
        embedded_in :calculation
        embeds_many :left_products, class_name: "VProduct"
        embeds_many :right_products, class_name: "VProduct"
      end
      
      # The Problem
      
      a = Calculation.new
      a.build_subcalculation
      a.subcalculation.left_products << [VProduct.first]
      a.subcalculation.left_products << [VProduct.last]
      a.subcalculation.left_products.count
      => 2
      a.save
      =>true
      # works fine :-) sweet
      # BUT
      
      a.subcalculation.left_products << [VProduct.where(vid: 45).first]
      =>true
      a.subcalculation.left_products.count
      => 3
      a.changed?
      => false
      a.subcalculation.changed?
      =>false
      a.save
      =>true
      
      # But it doenst save the new product. 
      # so i guess the dirty/change-tracking has a bug.
      
      # best regards
      # im using mongoid 2.4.6 and rails 3.1.3
      
      

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

              Created:
              Updated:
              Resolved: