Module: SchemaAssociations::ActiveRecord::Associations

Defined in:
lib/schema_associations/active_record/associations.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Relation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

:nodoc:



18
19
20
21
22
23
24
25
# File 'lib/schema_associations/active_record/associations.rb', line 18

def self.extended(base) #:nodoc:
  class << base
    alias_method_chain :reflect_on_association, :schema_associations
    alias_method_chain :_reflect_on_association, :schema_associations if method_defined? :_reflect_on_association
    alias_method_chain :reflect_on_all_associations, :schema_associations
  end
  ::ActiveRecord::Relation.send :include, Relation if defined? ::ActiveRecord::Relation
end

Instance Method Details

#_reflect_on_association_with_schema_associations(*args) ⇒ Object

introduced in rails 4.1



33
34
35
36
# File 'lib/schema_associations/active_record/associations.rb', line 33

def _reflect_on_association_with_schema_associations(*args) #:nodoc:
  _load_schema_associations_associations
  _reflect_on_association_without_schema_associations(*args)
end

#define_attribute_methods(*args) ⇒ Object

:nodoc:



43
44
45
46
# File 'lib/schema_associations/active_record/associations.rb', line 43

def define_attribute_methods(*args) #:nodoc:
  super
  _load_schema_associations_associations
end

#reflect_on_all_associations_with_schema_associations(*args) ⇒ Object

:nodoc:



38
39
40
41
# File 'lib/schema_associations/active_record/associations.rb', line 38

def reflect_on_all_associations_with_schema_associations(*args) #:nodoc:
  _load_schema_associations_associations
  reflect_on_all_associations_without_schema_associations(*args)
end

#reflect_on_association_with_schema_associations(*args) ⇒ Object

:nodoc:



27
28
29
30
# File 'lib/schema_associations/active_record/associations.rb', line 27

def reflect_on_association_with_schema_associations(*args) #:nodoc:
  _load_schema_associations_associations
  reflect_on_association_without_schema_associations(*args)
end

#schema_associations(opts = {}) ⇒ Object

Per-model override of Config options. Use via, e.g.

class MyModel < ActiveRecord::Base
    schema_associations :auto_create => false
end

If :auto_create is not specified, it is implicitly specified as true. This allows the “non-invasive” style of using SchemaAssociations in which you set the global Config to auto_create = false, then in any model that you want auto associations you simply do:

   class MyModel < ActiveRecord::Base
       schema_associations
   end

Of course other options can be passed, such as

   class MyModel < ActiveRecord::Base
       schema_associations :concise_names => false, :except_type => :has_and_belongs_to_many
   end


70
71
72
# File 'lib/schema_associations/active_record/associations.rb', line 70

def schema_associations(opts={})
  @schema_associations_config = SchemaAssociations.config.merge({:auto_create => true}.merge(opts))
end

#schema_associations_configObject

:nodoc:



74
75
76
# File 'lib/schema_associations/active_record/associations.rb', line 74

def schema_associations_config # :nodoc:
  @schema_associations_config ||= SchemaAssociations.config.dup
end