Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1552

Field updated_at is not updated when an embedded document is changed

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Hi guys, I'm here again

      I have two models in my application:

      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

      Unable to find source-code formatter for language: c```. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
       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.

            Assignee:
            durran Durran Jordan
            Reporter:
            lucasas lucasas
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: