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

presence validator only applies on second save.

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.2
    • Affects Version/s: None
    • Component/s: None

      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.

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

              Created:
              Updated:
              Resolved: