1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/models/man.rb
Gannon McGibbon 61401184e9 Don't run callbacks on has_many inverse add
Stop running association callbacks when setting `has_many` inverse
records. The `before_add` and `after_add` callbacks are meant for
newly added records.
2019-10-10 16:18:13 -04:00

36 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class Man < ActiveRecord::Base
has_one :face, inverse_of: :man
has_one :polymorphic_face, class_name: "Face", as: :polymorphic_man, inverse_of: :polymorphic_man
has_one :polymorphic_face_without_inverse, class_name: "Face", as: :poly_man_without_inverse
has_many :interests, inverse_of: :man
has_many :interests_with_callbacks,
class_name: "Interest",
before_add: :add_called,
after_add: :add_called,
inverse_of: :man_with_callbacks
has_many :polymorphic_interests,
class_name: "Interest",
as: :polymorphic_man,
inverse_of: :polymorphic_man
has_many :polymorphic_interests_with_callbacks,
class_name: "Interest",
as: :polymorphic_man,
before_add: :add_called,
after_add: :add_called,
inverse_of: :polymorphic_man
# These are "broken" inverse_of associations for the purposes of testing
has_one :dirty_face, class_name: "Face", inverse_of: :dirty_man
has_many :secret_interests, class_name: "Interest", inverse_of: :secret_man
has_one :mixed_case_monkey
attribute :add_callback_called, :boolean, default: false
def add_called(_interest)
self.add_callback_called = true
end
end
class Human < Man
end