mongoid/mongoid — Issue #1551: Field updated_at is not updated when an embedded document is changed
Author: lucasas
Created: 2012-01-04 17:14:50+00:00
State: open

Hi guys, I'm here again :P

I have two models in my application:

```ruby
class Parent
include Mongoid::Document
include Mongoid::Timestamps

field :name, :type => String
embeds_many :children
end

class Child
include Mongoid::Document
field :name, :type => String
end
```

Then I have created an instance for Parent and an instance for Child, like this:
```
p = Parent.create :name => "Lucas"
c = Child.new :name => "Clara"
```
The next step was include ```c``` into ```p```, but before I got ```updated_at``` from ```p```:
```
updated_at = p.updated_at
p.children << c
```
Then I had updated child's name and saved it:
```
p.children.first.name = "Clarinha"
p.children.first.save!
p.save!
```
Now the problem happens. If I call ```changed?``` on instance ```p```, it returns ```false```. And because of this, Mongoid does not generate a new ```updated_at``` value.

```
puts p.updated_at == updated_at # print true, but should be false.
```

Is it possible to solve this problem? If not, I'll have to do a uggly workaround here.

Thanks guys.