class Sequel::Model::Associations::AssociationReflection
be instantiated by the user.
provides methods to reduce internal code duplication. It should not
AssociationReflection is a Hash subclass that keeps information on Sequel::Model associations. It
def _add_method
def _add_method :"_add_#{singularize(self[:name])}" end
def _dataset_method
def _dataset_method :"_#{self[:name]}_dataset" end
def _remove_all_method
def _remove_all_method :"_remove_all_#{self[:name]}" end
def _remove_method
def _remove_method :"_remove_#{singularize(self[:name])}" end
def _setter_method
def _setter_method :"_#{self[:name]}=" end
def add_method
def add_method :"add_#{singularize(self[:name])}" end
def associated_class
def associated_class self[:class] ||= constantize(self[:class_name]) end
def association_method
def association_method self[:name] end
def can_have_associated_objects?(obj)
object. Should be false if obj cannot have associated objects because
Whether this association can have associated objects, given the current
def can_have_associated_objects?(obj) true end
def dataset_helper_method
def dataset_helper_method :"_#{self[:name]}_dataset_helper" end
def dataset_method
def dataset_method :"#{self[:name]}_dataset" end
def dataset_need_primary_key?
def dataset_need_primary_key? true end
def eager_graph_lazy_dataset?
is false, the association won't respect the :eager_graph option
Whether to eagerly graph a lazy dataset, true by default. If this
def eager_graph_lazy_dataset? true end
def eager_limit_strategy
def eager_limit_strategy fetch(:_eager_limit_strategy) do self[:_eager_limit_strategy] = if self[:limit] case s = self.fetch(:eager_limit_strategy){self[:model].default_eager_limit_strategy || :ruby} when true ds = associated_class.dataset if ds.supports_window_functions? :window_function else :ruby end else s end else nil end end end
def eager_loading_use_associated_key?
By default associations do not need to select a key in an associated table
def eager_loading_use_associated_key? false end
def limit_and_offset
def limit_and_offset if (v = self[:limit]).is_a?(Array) v else [v, nil] end end
def need_associated_primary_key?
Whether the associated object needs a primary key to be added/removed,
def need_associated_primary_key? false end
def qualify(table, col)
Qualify +col+ with the given table name. If +col+ is an array of columns,
def qualify(table, col) transform(col){|k| SQL::QualifiedIdentifier.new(table, k)} end
def qualify_assoc(col)
def qualify_assoc(col) qualify(associated_class.table_name, col) end
def qualify_cur(col)
def qualify_cur(col) qualify(self[:model].table_name, col) end
def reciprocal
to populate reciprocal associations. For example, when you do this_artist.add_album(album)
Artist.one_to_many :albums are reciprocal associations. This information is
of the current association. For example, Album.many_to_one :artist and
association is the association in the associated class that is the opposite
Returns the reciprocal association variable, if one exists. The reciprocal
def reciprocal return self[:reciprocal] if include?(:reciprocal) r_types = Array(reciprocal_type) keys = self[:keys] associated_class.all_association_reflections.each do |assoc_reflect| if r_types.include?(assoc_reflect[:type]) && assoc_reflect[:keys] == keys && assoc_reflect.associated_class == self[:model] self[:reciprocal_type] = assoc_reflect[:type] return self[:reciprocal] = assoc_reflect[:name] end end self[:reciprocal] = nil end
def reciprocal_array?
Whether the reciprocal of this association returns an array of objects instead of a single object,
def reciprocal_array? true end
def remove_all_method
def remove_all_method :"remove_all_#{self[:name]}" end
def remove_before_destroy?
Whether associated objects need to be removed from the association before
def remove_before_destroy? true end
def remove_method
def remove_method :"remove_#{singularize(self[:name])}" end
def remove_should_check_existing?
def remove_should_check_existing? false end
def returns_array?
Whether this association returns an array of objects instead of a single object,
def returns_array? true end
def select
def select self[:select] end
def set_reciprocal_to_self?
Whether to set the reciprocal association to self when loading associated
def set_reciprocal_to_self? false end
def setter_method
def setter_method :"#{self[:name]}=" end
def transform(s)
If +s+ is an array, map +s+ over the block. Otherwise, just call the
def transform(s) s.is_a?(Array) ? s.map(&Proc.new) : (yield s) end