Class: ActiveScaffold::DataStructures::Association::ActiveRecord

Inherits:
Abstract
  • Object
show all
Defined in:
lib/active_scaffold/data_structures/association/active_record.rb

Instance Attribute Summary

Attributes inherited from Abstract

#reverse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#allow_join?, #belongs_to?, #collection?, #habtm?, #has_many?, #has_one?, #initialize, #inverse_for?, #klass, #polymorphic?, #reverse_association, #singular?, #through_collection?, #through_singular?

Constructor Details

This class inherits a constructor from ActiveScaffold::DataStructures::Association::Abstract

Class Method Details

.reflect_on_all_associations(klass) ⇒ Object



3
4
5
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 3

def self.reflect_on_all_associations(klass)
  klass.reflect_on_all_associations
end

Instance Method Details

#asObject



41
42
43
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 41

def as
  @association.options[:as]
end

#counter_cacheObject



37
38
39
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 37

def counter_cache
  @association.options[:counter_cache]
end

#counter_cache_hack?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 66

def counter_cache_hack?
  if has_many?
    Rails.version < '5.0' && as
  elsif belongs_to?
    counter_cache && (Rails.version >= '5.0' || !polymorphic?)
  end
end

#dependentObject



45
46
47
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 45

def dependent
  @association.options[:dependent]
end

#inverseObject

name of inverse



50
51
52
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 50

def inverse
  @association.inverse_of&.name
end

#inverse_klassObject



29
30
31
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 29

def inverse_klass
  @association.active_record
end

#primary_keyObject



33
34
35
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 33

def primary_key
  @association.options[:primary_key]
end

#quoted_primary_keyObject



58
59
60
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 58

def quoted_primary_key
  @association.klass.quoted_primary_key
end

#quoted_table_nameObject



54
55
56
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 54

def quoted_table_name
  @association.klass.quoted_table_name
end

#readonly?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 13

def readonly?
  scope_values[:readonly]
end

#respond_to_target?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 62

def respond_to_target?
  true
end

#scopeObject



25
26
27
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 25

def scope
  @association.scope
end

#source_reflectionObject



21
22
23
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 21

def source_reflection
  @association.source_reflection if through?
end

#through?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 9

def through?
  @association.options[:through].present?
end

#through_reflectionObject



17
18
19
# File 'lib/active_scaffold/data_structures/association/active_record.rb', line 17

def through_reflection
  @association.through_reflection if through?
end