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

Unexpected after_add/before_add behavior in has_many or may be others relations too

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.2
    • Affects Version/s: None
    • Component/s: None
    • None

      I have two models Partner and Order. Partner has_many orders.
      So in Partner relation I declared before_add callback.
      So it works in normal way, but also if we calling methods like this

      Unable to find source-code formatter for language: order. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      .partner

      it's called too.

      class Partner
      field :order_index, type: Integer, default: 0
      has_many :orders, before_add: :inc_order_index

      private

      def inc_order_index
      self.inc(order_index: 1)
      end

      end

      class Order
      belongs_to :partner
      end

      only place when order_index is changed is in this callback.

      Do you have some ideas what's happen wrong?

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            mpospelov mpospelov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: