| Class | Sequel::Model::Associations::AssociationReflection |
| In: |
lib/sequel/model/associations.rb
|
| Parent: | Hash |
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.
Name symbol for the _add internal association method
# File lib/sequel/model/associations.rb, line 21
21: def _add_method
22:
23: "_add_#{singularize(self[:name])}"
24: end
Name symbol for the _dataset association method
# File lib/sequel/model/associations.rb, line 26
26: def _dataset_method
27:
28: "_#{self[:name]}_dataset"
29: end
Name symbol for the _remove_all internal association method
# File lib/sequel/model/associations.rb, line 31
31: def _remove_all_method
32:
33: "_remove_all_#{self[:name]}"
34: end
Name symbol for the _remove internal association method
# File lib/sequel/model/associations.rb, line 36
36: def _remove_method
37:
38: "_remove_#{singularize(self[:name])}"
39: end
Name symbol for the _setter association method
# File lib/sequel/model/associations.rb, line 41
41: def _setter_method
42:
43: "_#{self[:name]}="
44: end
Name symbol for the add association method
# File lib/sequel/model/associations.rb, line 46
46: def add_method
47:
48: "add_#{singularize(self[:name])}"
49: end
The class associated to the current model class via this association
# File lib/sequel/model/associations.rb, line 56
56: def associated_class
57: self[:class] ||= constantize(self[:class_name])
58: end
Name symbol for association method, the same as the name of the association.
# File lib/sequel/model/associations.rb, line 51
51: def association_method
52: self[:name]
53: end
Whether this association can have associated objects, given the current object. Should be false if obj cannot have associated objects because the necessary key columns are NULL.
# File lib/sequel/model/associations.rb, line 63
63: def can_have_associated_objects?(obj)
64: true
65: end
Name symbol for the _helper internal association method
# File lib/sequel/model/associations.rb, line 73
73: def dataset_helper_method
74:
75: "_#{self[:name]}_dataset_helper"
76: end
Name symbol for the dataset association method
# File lib/sequel/model/associations.rb, line 68
68: def dataset_method
69:
70: "#{self[:name]}_dataset"
71: end
Whether the dataset needs a primary key to function, true by default.
# File lib/sequel/model/associations.rb, line 78
78: def dataset_need_primary_key?
79: true
80: end
Whether to eagerly graph a lazy dataset, true by default. If this is false, the association won‘t respect the :eager_graph option when loading the association for a single record.
# File lib/sequel/model/associations.rb, line 112
112: def eager_graph_lazy_dataset?
113: true
114: end
The eager limit strategy to use for this dataset.
# File lib/sequel/model/associations.rb, line 83
83: def eager_limit_strategy
84: fetch(:_eager_limit_strategy) do
85: self[:_eager_limit_strategy] = if self[:limit]
86: case s = self.fetch(:eager_limit_strategy){self[:model].default_eager_limit_strategy || :ruby}
87: when true
88: ds = associated_class.dataset
89: if ds.supports_window_functions?
90: :window_function
91: else
92: :ruby
93: end
94: else
95: s
96: end
97: else
98: nil
99: end
100: end
101: end
The limit and offset for this association (returned as a two element array).
# File lib/sequel/model/associations.rb, line 117
117: def limit_and_offset
118: if (v = self[:limit]).is_a?(Array)
119: v
120: else
121: [v, nil]
122: end
123: end
Whether the associated object needs a primary key to be added/removed, false by default.
# File lib/sequel/model/associations.rb, line 127
127: def need_associated_primary_key?
128: false
129: end
Qualify col with the given table name. If col is an array of columns, return an array of qualified columns.
# File lib/sequel/model/associations.rb, line 133
133: def qualify(table, col)
134: transform(col){|k| SQL::QualifiedIdentifier.new(table, k)}
135: end
Qualify col with the associated model‘s table name.
# File lib/sequel/model/associations.rb, line 138
138: def qualify_assoc(col)
139: qualify(associated_class.table_name, col)
140: end
Qualify col with the current model‘s table name.
# File lib/sequel/model/associations.rb, line 143
143: def qualify_cur(col)
144: qualify(self[:model].table_name, col)
145: end
Returns the reciprocal association variable, if one exists. The reciprocal association is the association in the associated class that is the opposite of the current association. For example, Album.many_to_one :artist and Artist.one_to_many :albums are reciprocal associations. This information is to populate reciprocal associations. For example, when you do this_artist.add_album(album) it sets album.artist to this_artist.
# File lib/sequel/model/associations.rb, line 153
153: def reciprocal
154: return self[:reciprocal] if include?(:reciprocal)
155: r_types = Array(reciprocal_type)
156: keys = self[:keys]
157: associated_class.all_association_reflections.each do |assoc_reflect|
158: if r_types.include?(assoc_reflect[:type]) && assoc_reflect[:keys] == keys && assoc_reflect.associated_class == self[:model]
159: self[:reciprocal_type] = assoc_reflect[:type]
160: return self[:reciprocal] = assoc_reflect[:name]
161: end
162: end
163: self[:reciprocal] = nil
164: end
Whether the reciprocal of this association returns an array of objects instead of a single object, true by default.
# File lib/sequel/model/associations.rb, line 168
168: def reciprocal_array?
169: true
170: end
Name symbol for the remove_all_ association method
# File lib/sequel/model/associations.rb, line 173
173: def remove_all_method
174:
175: "remove_all_#{self[:name]}"
176: end
Whether associated objects need to be removed from the association before being destroyed in order to preserve referential integrity.
# File lib/sequel/model/associations.rb, line 179
179: def remove_before_destroy?
180: true
181: end
Name symbol for the remove_ association method
# File lib/sequel/model/associations.rb, line 184
184: def remove_method
185:
186: "remove_#{singularize(self[:name])}"
187: end
Whether to check that an object to be disassociated is already associated to this object, false by default.
# File lib/sequel/model/associations.rb, line 189
189: def remove_should_check_existing?
190: false
191: end
Whether this association returns an array of objects instead of a single object, true by default.
# File lib/sequel/model/associations.rb, line 195
195: def returns_array?
196: true
197: end
Whether to set the reciprocal association to self when loading associated records, false by default.
# File lib/sequel/model/associations.rb, line 206
206: def set_reciprocal_to_self?
207: false
208: end