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

Validates on has_and_belongs_to many relations stop sync

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

      class Coin
      include Mongoid::Document
      has_and_belongs_to_many :boxes
      validates :boxes, presence: true
      end

      class Box
      include Mongoid::Document
      has_and_belongs_to_many :coins
      end

      >> 2.times

      { Coin.create }

      >> Box.create

      { coins: [Coin.first,Coin.last] }

      When I type Coin.first.boxes and Coin.last.boxes it returns "nil" in both cases instead of the box i have just created.

      This behaviour disappears by removing the validation in Coin, then it behaves as expected.

      (Using ruby 2.0)

            Assignee:
            arthurnn Arthur Nogueira Neves
            Reporter:
            ghost Deleted user
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: