Module: Torque::PostgreSQL::AutosaveAssociation::ClassMethods

Included in:
Torque::PostgreSQL
Defined in:
lib/torque/postgresql/autosave_association.rb

Instance Method Summary collapse

Instance Method Details

#add_autosave_association_callbacks(reflection) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/torque/postgresql/autosave_association.rb', line 5

def add_autosave_association_callbacks(reflection)
  return super unless reflection.macro.eql?(:belongs_to_many)

  save_method = :"autosave_associated_records_for_#{reflection.name}"
  define_non_cyclic_method(save_method) { save_belongs_to_many_array(reflection) }

  before_save(:before_save_collection_association)
  after_save(:after_save_collection_association) if ::ActiveRecord::Base
    .instance_methods.include?(:after_save_collection_association)

  before_create(save_method)
  before_update(save_method)

  define_autosave_validation_callbacks(reflection)
end