Module: ActiveRecord::Associations::ClassMethods

Defined in:
lib/ext_active_record/association_extensions.rb

Instance Method Summary collapse

Instance Method Details

#create_belongs_to_reflection(association_id, options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ext_active_record/association_extensions.rb', line 52

def create_belongs_to_reflection(association_id, options)
  options.assert_valid_keys(
    :class_name, :foreign_key, :foreign_type, :remote, :conditions, :order, :include, :dependent, 
    :counter_cache, :extend, :polymorphic,
    :mirror_db_connection
  )
  
  reflection = create_reflection(:belongs_to, association_id, options, self)

  if options[:polymorphic]
    reflection.options[:foreign_type] ||= reflection.class_name.underscore + "_type"
  end

  reflection
end

#create_has_and_belongs_to_many_reflection(association_id, options, &extension) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ext_active_record/association_extensions.rb', line 68

def create_has_and_belongs_to_many_reflection(association_id, options, &extension)
  options.assert_valid_keys(
    :class_name, :table_name, :join_table, :foreign_key, :association_foreign_key, 
    :select, :conditions, :include, :order, :group, :limit, :offset,
    :uniq, 
    :finder_sql, :delete_sql, :insert_sql,
    :before_add, :after_add, :before_remove, :after_remove, 
    :extend,
    :mirror_db_connection
  )

  options[:extend] = create_extension_module(association_id, extension) if block_given?

  reflection = create_reflection(:has_and_belongs_to_many, association_id, options, self)

  reflection.options[:join_table] ||= join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(reflection.class_name))
  
  reflection
end

#create_has_many_reflection(association_id, options, &extension) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ext_active_record/association_extensions.rb', line 25

def create_has_many_reflection(association_id, options, &extension)
  options.assert_valid_keys(
    :class_name, :table_name, :foreign_key,
    :exclusively_dependent, :dependent,
    :select, :conditions, :include, :order, :group, :limit, :offset,
    :as, :through, :source, :source_type,
    :uniq,
    :finder_sql, :counter_sql, 
    :before_add, :after_add, :before_remove, :after_remove, 
    :extend,
    :mirror_db_connection
  )

  options[:extend] = create_extension_module(association_id, extension) if block_given?

  create_reflection(:has_many, association_id, options, self)
end

#create_has_one_reflection(association_id, options) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/ext_active_record/association_extensions.rb', line 43

def create_has_one_reflection(association_id, options)
  options.assert_valid_keys(
    :class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as,
    :mirror_db_connection
  )

  create_reflection(:has_one, association_id, options, self)
end