Class: Sequel::Model::Associations::AssociationReflection
- Includes:
- Inflections
- 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.
Direct Known Subclasses
ManyToManyAssociationReflection, ManyToOneAssociationReflection, OneToManyAssociationReflection
Instance Method Summary collapse
-
#_add_method ⇒ Object
Name symbol for add internal association method.
-
#_dataset_method ⇒ Object
Name symbol for _dataset association method.
-
#_remove_all_method ⇒ Object
Name symbol for _remove_all internal association method.
-
#_remove_method ⇒ Object
Name symbol for remove internal association method.
-
#_setter_method ⇒ Object
Name symbol for setter association method.
-
#add_method ⇒ Object
Name symbol for add_ association method.
-
#associated_class ⇒ Object
The class associated to the current model class via this association.
-
#association_method ⇒ Object
Name symbol for association method, the same as the name of the association.
-
#dataset_helper_method ⇒ Object
Name symbol for _helper internal association method.
-
#dataset_method ⇒ Object
Name symbol for dataset association method.
-
#dataset_need_primary_key? ⇒ Boolean
Whether the dataset needs a primary key to function, true by default.
-
#eager_graph_lazy_dataset? ⇒ Boolean
Whether to eagerly graph a lazy dataset, true by default.
-
#need_associated_primary_key? ⇒ Boolean
Whether the associated object needs a primary key to be added/removed, false by default.
-
#reciprocal ⇒ Object
Returns/sets the reciprocal association variable, if one exists.
-
#reciprocal_array? ⇒ Boolean
Whether the reciprocal of this association returns an array of objects instead of a single object, true by default.
-
#remove_all_method ⇒ Object
Name symbol for remove_all_ association method.
-
#remove_method ⇒ Object
Name symbol for remove_ association method.
-
#returns_array? ⇒ Boolean
Whether this association returns an array of objects instead of a single object, true by default.
-
#select ⇒ Object
The columns to select when loading the association, nil by default.
-
#set_reciprocal_to_self? ⇒ Boolean
By default, associations shouldn’t set the reciprocal association to self.
-
#setter_method ⇒ Object
Name symbol for setter association method.
Methods included from Inflections
clear, irregular, plural, singular, uncountable
Methods inherited from Hash
#&, #case, #sql_expr, #sql_negate, #sql_or, #|, #~
Instance Method Details
#_add_method ⇒ Object
Name symbol for add internal association method
12 13 14 |
# File 'lib/sequel/model/association_reflection.rb', line 12 def _add_method :"_add_#{singularize(self[:name])}" end |
#_dataset_method ⇒ Object
Name symbol for _dataset association method
17 18 19 |
# File 'lib/sequel/model/association_reflection.rb', line 17 def _dataset_method :"_#{self[:name]}_dataset" end |
#_remove_all_method ⇒ Object
Name symbol for _remove_all internal association method
22 23 24 |
# File 'lib/sequel/model/association_reflection.rb', line 22 def _remove_all_method :"_remove_all_#{self[:name]}" end |
#_remove_method ⇒ Object
Name symbol for remove internal association method
27 28 29 |
# File 'lib/sequel/model/association_reflection.rb', line 27 def _remove_method :"_remove_#{singularize(self[:name])}" end |
#_setter_method ⇒ Object
Name symbol for setter association method
32 33 34 |
# File 'lib/sequel/model/association_reflection.rb', line 32 def _setter_method :"_#{self[:name]}=" end |
#add_method ⇒ Object
Name symbol for add_ association method
37 38 39 |
# File 'lib/sequel/model/association_reflection.rb', line 37 def add_method :"add_#{singularize(self[:name])}" end |
#associated_class ⇒ Object
The class associated to the current model class via this association
47 48 49 |
# File 'lib/sequel/model/association_reflection.rb', line 47 def associated_class self[:class] ||= constantize(self[:class_name]) end |
#association_method ⇒ Object
Name symbol for association method, the same as the name of the association.
42 43 44 |
# File 'lib/sequel/model/association_reflection.rb', line 42 def association_method self[:name] end |
#dataset_helper_method ⇒ Object
Name symbol for _helper internal association method
57 58 59 |
# File 'lib/sequel/model/association_reflection.rb', line 57 def dataset_helper_method :"_#{self[:name]}_dataset_helper" end |
#dataset_method ⇒ Object
Name symbol for dataset association method
52 53 54 |
# File 'lib/sequel/model/association_reflection.rb', line 52 def dataset_method :"#{self[:name]}_dataset" end |
#dataset_need_primary_key? ⇒ Boolean
Whether the dataset needs a primary key to function, true by default.
62 63 64 |
# File 'lib/sequel/model/association_reflection.rb', line 62 def dataset_need_primary_key? true end |
#eager_graph_lazy_dataset? ⇒ Boolean
Whether to eagerly graph a lazy dataset, true by default.
67 68 69 |
# File 'lib/sequel/model/association_reflection.rb', line 67 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.
73 74 75 |
# File 'lib/sequel/model/association_reflection.rb', line 73 def need_associated_primary_key? false end |
#reciprocal ⇒ Object
Returns/sets the reciprocal association variable, if one exists
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sequel/model/association_reflection.rb', line 78 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.
92 93 94 |
# File 'lib/sequel/model/association_reflection.rb', line 92 def reciprocal_array? true end |
#remove_all_method ⇒ Object
Name symbol for remove_all_ association method
97 98 99 |
# File 'lib/sequel/model/association_reflection.rb', line 97 def remove_all_method :"remove_all_#{self[:name]}" end |
#remove_method ⇒ Object
Name symbol for remove_ association method
102 103 104 |
# File 'lib/sequel/model/association_reflection.rb', line 102 def remove_method :"remove_#{singularize(self[:name])}" end |
#returns_array? ⇒ Boolean
Whether this association returns an array of objects instead of a single object, true by default.
108 109 110 |
# File 'lib/sequel/model/association_reflection.rb', line 108 def returns_array? true end |
#select ⇒ Object
The columns to select when loading the association, nil by default.
113 114 115 |
# File 'lib/sequel/model/association_reflection.rb', line 113 def select self[:select] end |
#set_reciprocal_to_self? ⇒ Boolean
By default, associations shouldn’t set the reciprocal association to self.
118 119 120 |
# File 'lib/sequel/model/association_reflection.rb', line 118 def set_reciprocal_to_self? false end |
#setter_method ⇒ Object
Name symbol for setter association method
123 124 125 |
# File 'lib/sequel/model/association_reflection.rb', line 123 def setter_method :"#{self[:name]}=" end |