Module: LowCardTables::HasLowCardTable::Base

Extended by:
ActiveSupport::Concern
Defined in:
lib/low_card_tables/has_low_card_table/base.rb

Overview

This module gets included (once) into any class that has declared a reference to at least one low-card table, using #has_low_card_table. It is just a holder for several related objects that do all the actual work of implementing the referring side of the low-card system.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_low_card_objects_managerObject

Returns the LowCardObjectsManager, which is responsible for maintaining the set of low-card objects accessed by this model object – the instances of the low-card class that are “owned” by this object. See that class’s documentation for more information.



209
210
211
# File 'lib/low_card_tables/has_low_card_table/base.rb', line 209

def _low_card_objects_manager
  @_low_card_objects_manager ||= LowCardTables::HasLowCardTable::LowCardObjectsManager.new(self)
end

#ensure_proper_typeObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/low_card_tables/has_low_card_table/base.rb', line 63

def ensure_proper_type
  if (assn = self.class.association_for_inheritance_column)
    superclass = self.class.superclass
    unless (superclass == ::ActiveRecord::Base) || (superclass.abstract_class?)
      lco = send(assn.association_name)
      lco.send(:write_attribute, self.class.inheritance_column, self.class.sti_name)
    end
  else
    super
  end
end

#low_card_update_foreign_keys!Object

Updates the current values of all low-card reference columns according to the current attributes. This is automatically called in a #before_save hook; you can also call it yourself at any time. Note that this can cause new low-card rows to be created, if the current combination of attributes for a given low-card table has not been used before.



202
203
204
# File 'lib/low_card_tables/has_low_card_table/base.rb', line 202

def low_card_update_foreign_keys!
  self.class._low_card_associations_manager.low_card_update_foreign_keys!(self)
end