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

Since belongs to many is a collection, the callback would normally go to after_create. However, since it is a belongs_to kind of association, it neds to be executed before_save



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/torque/postgresql/autosave_association.rb', line 10

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) do
    save_belongs_to_many_association(reflection)
  end

  before_save(save_method)

  define_autosave_validation_callbacks(reflection)
end