Class: Sequel::Model::Associations::AssociationReflection

Inherits:
Hash
  • Object
show all
Defined in:
lib/sequel_model/association_reflection.rb

Overview

AssociationReflection is a Hash subclass that keeps information on Sequel::Model associations. It provides methods to reduce internal code duplication. It should not be instantiated by the user.

Instance Method Summary collapse

Methods inherited from Hash

#&, #case, #sql_expr, #sql_negate, #sql_or, #|, #~

Instance Method Details

#_add_methodObject

Name symbol for add internal association method



10
11
12
# File 'lib/sequel_model/association_reflection.rb', line 10

def _add_method
  :"_add_#{self[:name].to_s.singularize}"
end

#_dataset_methodObject

Name symbol for _dataset association method



15
16
17
# File 'lib/sequel_model/association_reflection.rb', line 15

def _dataset_method
  :"_#{self[:name]}_dataset"
end

#_remove_all_methodObject

Name symbol for _remove_all internal association method



20
21
22
# File 'lib/sequel_model/association_reflection.rb', line 20

def _remove_all_method
  :"_remove_all_#{self[:name]}"
end

#_remove_methodObject

Name symbol for remove internal association method



25
26
27
# File 'lib/sequel_model/association_reflection.rb', line 25

def _remove_method
  :"_remove_#{self[:name].to_s.singularize}"
end

#_setter_methodObject

Name symbol for setter association method



30
31
32
# File 'lib/sequel_model/association_reflection.rb', line 30

def _setter_method
  :"_#{self[:name]}="
end

#add_methodObject

Name symbol for add_ association method



35
36
37
# File 'lib/sequel_model/association_reflection.rb', line 35

def add_method
  :"add_#{self[:name].to_s.singularize}"
end

#associated_classObject

The class associated to the current model class via this association



45
46
47
# File 'lib/sequel_model/association_reflection.rb', line 45

def associated_class
  self[:class] ||= self[:class_name].constantize
end

#association_methodObject

Name symbol for association method, the same as the name of the association.



40
41
42
# File 'lib/sequel_model/association_reflection.rb', line 40

def association_method
  self[:name]
end

#dataset_helper_methodObject

Name symbol for _helper internal association method



55
56
57
# File 'lib/sequel_model/association_reflection.rb', line 55

def dataset_helper_method
  :"_#{self[:name]}_dataset_helper"
end

#dataset_methodObject

Name symbol for dataset association method



50
51
52
# File 'lib/sequel_model/association_reflection.rb', line 50

def dataset_method
  :"#{self[:name]}_dataset"
end

#dataset_need_primary_key?Boolean

Whether the dataset needs a primary key to function, true by default.

Returns:

  • (Boolean)


60
61
62
# File 'lib/sequel_model/association_reflection.rb', line 60

def dataset_need_primary_key?
  true
end

#eager_graph_lazy_dataset?Boolean

Whether to eagerly graph a lazy dataset, true by default.

Returns:

  • (Boolean)


65
66
67
# File 'lib/sequel_model/association_reflection.rb', line 65

def eager_graph_lazy_dataset?
  true
end

#need_associated_primary_key?Boolean

Whether the associated object needs a primary key to be added/removed, false by default.

Returns:

  • (Boolean)


71
72
73
# File 'lib/sequel_model/association_reflection.rb', line 71

def need_associated_primary_key?
  false
end

#reciprocalObject

Returns/sets the reciprocal association variable, if one exists



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sequel_model/association_reflection.rb', line 76

def reciprocal
  return self[:reciprocal] if include?(:reciprocal)
  r_type = reciprocal_type
  key = self[:key]
  associated_class.all_association_reflections.each do |assoc_reflect|
    if assoc_reflect[:type] == r_type && assoc_reflect[:key] == key
      return self[:reciprocal] = assoc_reflect[:name]
    end
  end
  self[:reciprocal] = nil
end

#reciprocal_array?Boolean

Whether the reciprocal of this association returns an array of objects instead of a single object, true by default.

Returns:

  • (Boolean)


90
91
92
# File 'lib/sequel_model/association_reflection.rb', line 90

def reciprocal_array?
  true
end

#remove_all_methodObject

Name symbol for remove_all_ association method



95
96
97
# File 'lib/sequel_model/association_reflection.rb', line 95

def remove_all_method
  :"remove_all_#{self[:name]}"
end

#remove_methodObject

Name symbol for remove_ association method



100
101
102
# File 'lib/sequel_model/association_reflection.rb', line 100

def remove_method
  :"remove_#{self[:name].to_s.singularize}"
end

#returns_array?Boolean

Whether this association returns an array of objects instead of a single object, true by default.

Returns:

  • (Boolean)


106
107
108
# File 'lib/sequel_model/association_reflection.rb', line 106

def returns_array?
  true
end

#selectObject

The columns to select when loading the association, nil by default.



111
112
113
# File 'lib/sequel_model/association_reflection.rb', line 111

def select
  self[:select]
end

#set_reciprocal_to_self?Boolean

By default, associations shouldn’t set the reciprocal association to self.

Returns:

  • (Boolean)


116
117
118
# File 'lib/sequel_model/association_reflection.rb', line 116

def set_reciprocal_to_self?
  false
end

#setter_methodObject

Name symbol for setter association method



121
122
123
# File 'lib/sequel_model/association_reflection.rb', line 121

def setter_method
  :"#{self[:name]}="
end