module Torque::PostgreSQL::AutosaveAssociation::ClassMethods

Public Instance Methods

add_autosave_association_callbacks(reflection) click to toggle source

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

Calls superclass method
# 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