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

presence validator only applies on second save.

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 5.0.2
    • None

    Description

      If I have a document with many embedded documents:

      class Pack
        include Mongoid::Document
       
        embeds_many :items
        validates_presence_of :items
        accepts_nested_attributes_for :items,
                                      allow_destroy: true
      end
      

      I can destroy all the items, with the standard rails _destroy option used with update_attributes:

      @pack.update_attributes params[:pack]
      

      At this point, the pack will have no items. If then I make a second edit to the pack, changing some other field, then the validator will activate and prevent the save.

      Presumably this is because the items are individually destroyed, rather than perhaps being marked as to_destroy, and then actually destroyed with the parent document is saved.

      Attachments

        Issue Links

          Activity

            People

              durran.jordan@mongodb.com Durran Jordan
              pehrlich pehrlich
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: