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

Children validate referenced parent documents

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.1.9
    • Affects Version/s: None
    • Component/s: None

      The doc page that discusses relation validations says that Mongoid validates child relations by default (IE: has_one, has_many, embeds_one, etc). I'm finding that parent relations are also validated by default:

      class Parent
        include Mongoid::Document
      
        has_many :children
      
        def valid?(*args)
          puts '*** Parent#valid?'
          super
        end 
      end
      
      class Child
        include Mongoid::Document
      
        belongs_to :parent
      
        def valid?(*args)
          puts '*** Child#valid?'
          super
        end 
      end
      
      Child.reflect_on_association(:parent).validate?
      => true
      
      p = Parent.new
      c = Child.new :parent => p
      c.valid?
      *** Child#valid?
      *** Parent#valid?
      => true
      

      Is this the desired behaviour?

            Assignee:
            Unassigned Unassigned
            Reporter:
            nickh Nick Hoffman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: