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

Have presence validator on relation respect autosave = false

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

      The patch for issue MONGOID-1676 changed the behavior of the presence validator so that it enables autosave on the relation. However, there are circumstances where this is undesirable. The only way to get around this it to assign the presence validator before the relation which is a bit clunky.

      This patch allows you to explicitly set the autosave field on the relation to false to disable this behavior. If you do not specify anything for autosave, or set it to true, it will apply the current behavior. For example:

      class Tag
        include Mongoid::Document
        belongs_to :post
      end
      
      class Post
        include Mongoid::Document
        has_many :tags, autosave: false
        validates_presence_of :tags # does not enable autosave on tags
      end
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            jingoro jingoro
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: