-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
if you have an array field with a a :default => [] and a validation in place, when you update the array attribute by replacing the array, the change won't get saved.
attached is a set of failing specs in the spec/functional/mongoid/array_validation_spec.rb file. these specs demonstrate the problem from both a functional standpoint and from the perspective of the internals, where the problem is caused.
the strange thing is, it's a line in ActiveModel::Errors, line # 223, that causes this. that line is:
[attributes].flatten.each do |attribute|
`
I'm baffled by this - but when you grab a reference to the model's #attributes and then stuff it into an array, flatten it, and iterate it (even if the iteration does nothing), then the model's #changes concerning the array attribute are destroyed.
i've outlined this scenario in one of the specs, directly, so you can see what's happening. unfortunately i wasn't able to figure out why this is happening, so i couldn't fix it. i'll continue to look at this when i have time, but i wanted to get the failing specs pushed up so that someone else can look at it if they have a chance.
one other note: this branch includes the fixes i submitted for MONGOID-1044. not sure if that matters, just wanted to let you know.