mongoid/mongoid — Issue #1790: embeds_many - changes are saved in the wrong document
Author: banditj
Created: 2012-03-06 16:56:37+00:00
State: open

# 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.last
a.name
=>"test"
a.subcalculation.left_products.first.name
=>"hugo"
a.subcalculation.left_products.first.name="test123"
a.save
=>true
a = Calculation.last
a.name
=>"test123"
a.subcalculation.left_products.first.name
=>"hugo"