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
Name symbol for the _helper internal association method
# File lib/sequel/model/associations.rb, line 67 67: def dataset_helper_method 68: 69: "_#{self[:name]}_dataset_helper" 70: end
Name symbol for the dataset association method
# File lib/sequel/model/associations.rb, line 62 62: def dataset_method 63: 64: "#{self[:name]}_dataset" 65: end
Whether the dataset needs a primary key to function, true by default.
# File lib/sequel/model/associations.rb, line 72 72: def dataset_need_primary_key? 73: true 74: 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 85 85: def eager_graph_lazy_dataset? 86: true 87: end
Whether the associated object needs a primary key to be added/removed, false by default.
# File lib/sequel/model/associations.rb, line 91 91: def need_associated_primary_key? 92: false 93: 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 101 101: def reciprocal 102: return self[:reciprocal] if include?(:reciprocal) 103: r_type = reciprocal_type 104: key = self[:key] 105: associated_class.all_association_reflections.each do |assoc_reflect| 106: if assoc_reflect[:type] == r_type && assoc_reflect[:key] == key && assoc_reflect.associated_class == self[:model] 107: return self[:reciprocal] = assoc_reflect[:name] 108: end 109: end 110: self[:reciprocal] = nil 111: 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 115 115: def reciprocal_array? 116: true 117: end
Name symbol for the remove_all_ association method
# File lib/sequel/model/associations.rb, line 120 120: def remove_all_method 121: 122: "remove_all_#{self[:name]}" 123: end
Name symbol for the remove_ association method
# File lib/sequel/model/associations.rb, line 125 125: def remove_method 126: 127: "remove_#{singularize(self[:name])}" 128: end
Whether this association returns an array of objects instead of a single object, true by default.
# File lib/sequel/model/associations.rb, line 131 131: def returns_array? 132: true 133: end
Whether to set the reciprocal association to self when loading associated records, false by default.
# File lib/sequel/model/associations.rb, line 142 142: def set_reciprocal_to_self? 143: false 144: end