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

Don't to allow saves documents if the child is invalid

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

      I have two models:

      class Book
      include Mongoid::Document
      field :title
      field :author
      embeds_many :chapters
      validates_presence_of :title
      end

      =========================

      class Chapter
      include Mongoid::Document
      field :name
      field :content
      validates_presence_of :name
      embedded_in :book,:inverse_of => :chapters
      end

      the bug is when I do this:

      p = Book.new(:title => "New Title", :author => "New Author")
      p.chapters << Chapter.new
      p.save
      true

      in other words, apparently, Mongoid don't work like ActiveRecord or
      MongoMapper that does not allow saves documents if their child
      classes are not valid..
      beyond that, the AR and MongoMapper throw the validation errors to
      the parent class errors... thats allow to show the erros using the
      same form_for

      thanks!

            Assignee:
            Unassigned Unassigned
            Reporter:
            nonato Nen Nonato
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: