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

.as_document does not generate Timestamps

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • None

      I dont know if this is a bug or not.
      I use .as_document to do batch insertion of documents, but it does not generates the created_at field

      example:

      class Person
        include Mongoid::Document
        include Mongoid::Timestamps
      end
      
      person = Person.new
      
      person.as_document
       => {"_id"=>"5359ffe5f12a9ca3c4000001"}
      
      Person.collection.insert([person.as_document])
      
      Person.last.created_at
       => nil
      

      arthurnn should it be fixed with pull request?
      I've tried patching the method "as_document" in document.rb

      with this:

      if new_record? && self.class.include?(Mongoid::Timestamps::Created)
        set_created_at
      end
      

      but timeless specs will fail because of the timeless! scope examples

            Assignee:
            dianna.hohensee@mongodb.com Dianna Hohensee (Inactive)
            Reporter:
            fred fred
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: