Association :touch option value disregarded

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Major - P3
    • 6.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hi,

      I've spotted an incompatibility issue of the association's :touch option.
      While ActiveRecord association accepts a symbol specifying the timestamp attribute to update, Mongoid only updates updated_at disregarding the :touch option value.

      Example:

      class Post
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :title, type: String
        field :tags_changed_at, type: Time
      
        has_many :tags
      end
      
      class Tag
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :name, type: String
        belongs_to :post, touch: :tags_changed_at
      end
      
      p = Post.create(title: 'Party hard')
      t = p.tags.create(name: 'beer')
      p.tags_changed_at # => nil
      

      This can be fixed in Mongoid::Relations::Touchable#define_relation_touch_method by accepting optional :touch value.

      Should I open a pull request or there's somebody who can take this on?

              Assignee:
              Unassigned
              Reporter:
              Oleg Vivtash
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: