-
Type: Bug
-
Resolution: Cannot Reproduce
-
Priority: Major - P3
-
Affects Version/s: 5.1.4
-
Component/s: None
-
None
-
Environment:rvm 1.26.11
ruby 2.2.1p85
mongodb 3.2.8
class Business::Invoice
[...]
embeds_one :total_net_price, class_name: 'Business::Price'
validates :total_net_price, presence: true
embeds_one :total_price, class_name: 'Business::Price'
validates :total_price, presence: true
[...]
end
class Business::Price
[...]
field :value, type: Float, default: 0.0
validates :value,
presence: true,
numericality:
field :value_unrounded, type: Float, default: 0.0
validates :value_unrounded,
presence: true,
allow_blank: true,
numericality:
[...]
end
When creating an invoice i want to copy the prices from an order. So i want to do this:
invoice.build_total_price( value: order.total_price.value )
invoice.build_total_net_price( value: order.total_net_price.value )
When saving this invoice i get the following error:
NoMethodError: undefined method `each' for 214.99:Float
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/atomic/modifiers.rb:121:in `add_operation'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/atomic/modifiers.rb:87:in `block in set'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/atomic/modifiers.rb:84:in `each_pair'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/atomic/modifiers.rb:84:in `set'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/atomic.rb:351:in `generate_atomic_updates'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/atomic.rb:134:in `block in atomic_updates'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/atomic.rb:132:in `each'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/atomic.rb:132:in `atomic_updates'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/persistable/updatable.rb:93:in `init_atomic_updates'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/persistable/updatable.rb:140:in `block in update_document'
/home/ple/.rvm/gems/ruby-2.2.1@squibble-2016/gems/mongoid-5.1.4/lib/mongoid/persistable/updatable.rb:118:in `block (2 levels) in prepare_update'
When i replace the code from above and just copy the prices (dup) it works. The downside is to get the same ids for the prices on the invoice.
invoice.total_price = order.total_price
invoice.total_net_price = order.total_net_price
I get the same error when try to clone die prices. For me it looks like getting this error when trying to save an object with a new id?
Thanks in advance!
Kind regards
Patrick