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

Manipulations with associations ignores validation

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

      I have next classes
      <pre><code> class A
      include Mongoid::Document
      has_many :bs
      validates :bs, presence: true
      end

      class B
      include Mongoid::Document
      belongs_to :a
      end

      a = A.new
      a.valid? #false
      a.bs << B.new
      a.valid? #true
      B.count #0
      A.count #0
      a.save
      B.count MONGOID-4
      A.count MONGOID-4
      a.bs = []
      a.valid? #false
      A.first.bs.count #0, but I expect 1 record to be here
      </code></pre>

            Assignee:
            Unassigned Unassigned
            Reporter:
            Surzhko Surzhko [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: