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

Association :touch option value disregarded

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.0.0
    • Component/s: None
    • Labels:
      None
    • Sprint:
      Ruby Sprint 39, Ruby Sprint 40

      Description

      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?

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: