Validates on has_and_belongs_to many relations stop sync

XMLWordPrintableJSON

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

      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:
              Arthur Nogueira Neves
              Reporter:
              Deleted user
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: