mongoid/mongoid — Issue #1789: embeds_many - change tracking 
Author: banditj
Created: 2012-03-06 16:28:11+00:00
State: open

```ruby

# 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

```