Module: DrNicMagicModels::MagicModel

Included in:
ActiveRecord::Base
Defined in:
lib/dr_nic_magic_models/magic_model.rb

Overview

Mixed into a class that is dynamically created, unless the class was created by the Schema.load_schema process which builds the whole class, thus no magicalness is needed

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dr_nic_magic_models/magic_model.rb', line 6

def self.append_features(base)
  super
  base.send(:include, InstanceMethods)
  class << base
    # Returns the AssociationReflection object for the named +aggregation+ (use the symbol). Example:
    #   Account.reflect_on_association(:owner) # returns the owner AssociationReflection
    #   Invoice.reflect_on_association(:line_items).macro  # returns :has_many
    def reflect_on_association(association)
      unless reflections[association]
        # See if an assocation can be generated
        self.new.send(association) rescue nil
      end
      reflections[association].is_a?(ActiveRecord::Reflection::AssociationReflection) ? reflections[association] : nil
    end
  end
end