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

Support for the :touch option in relations

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

      Feature: Support :touch option in relations.

      class Person
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :name
      
        has_one :job, :touch => true
      end
      
      class Job
        include Mongoid::Document
        include Mongoid::Timestamps
      
        belongs_to :person, :touch => true
      end
      

      Given I have a person with a job.

        Person.work = Jon.new
      

      Saved

        Person.save
        Person.updated_at
          => 2012-03-07 19:03:15 +0100
      

      When I change person and save it, jon's update_at field is updated too:

        person.name = 'Cervantes'
        person.save
        person.updated_at
        => 2012-03-07 19:05:15 +0100
        job.updated_at
        => 2012-03-07 19:05:15 +0100
      

      I would like to use this to do key-based expiration caching. I need to be able to update timestamps in cascade to effectively do that.

      http://apidock.com/rails/ActiveRecord/Persistence/touch

            Assignee:
            Unassigned Unassigned
            Reporter:
            Nerian Gonzalo Rodríguez-Baltanás Díaz [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: