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

Class | Sequel::Model::Associations::AssociationReflection
In: | lib/sequel_model/association_reflection.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.

### Methods

_add_method _dataset_method _remove_all_method _remove_method _setter_method add_method associated_class association_method dataset_helper_method dataset_method dataset_need_primary_key? eager_graph_lazy_dataset? need_associated_primary_key? reciprocal reciprocal_array? remove_all_method remove_method returns_array? select set_reciprocal_to_self? setter_method

### Public Instance methods

_add_method()

Name symbol for add internal association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 10
    10:     def _add_method
    11:
    12:       "_add_#{self[:name].to_s.singularize}"
    13:     end

_dataset_method()

Name symbol for _dataset association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 15
    15:     def _dataset_method
    16:
    17:       "_#{self[:name]}_dataset"
    18:     end

_remove_all_method()

Name symbol for _remove_all internal association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 20
    20:     def _remove_all_method
    21:
    22:       "_remove_all_#{self[:name]}"
    23:     end

_remove_method()

Name symbol for remove internal association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 25
    25:     def _remove_method
    26:
    27:       "_remove_#{self[:name].to_s.singularize}"
    28:     end

_setter_method()

Name symbol for setter association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 30
    30:     def _setter_method
    31:
    32:       "_#{self[:name]}="
    33:     end

add_method()

Name symbol for add_ association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 35
    35:     def add_method
    36:
    37:       "add_#{self[:name].to_s.singularize}"
    38:     end

associated_class()

The class associated to the current model class via this association

[Source]

        # File lib/sequel_model/association_reflection.rb, line 45
    45:     def associated_class
    46:       self[:class] ||= self[:class_name].constantize
    47:     end

association_method()

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

[Source]

        # File lib/sequel_model/association_reflection.rb, line 40
    40:     def association_method
    41:       self[:name]
    42:     end

dataset_helper_method()

Name symbol for _helper internal association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 55
    55:     def dataset_helper_method
    56:
    57:       "_#{self[:name]}_dataset_helper"
    58:     end

dataset_method()

Name symbol for dataset association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 50
    50:     def dataset_method
    51:
    52:       "#{self[:name]}_dataset"
    53:     end

dataset_need_primary_key?()

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

[Source]

        # File lib/sequel_model/association_reflection.rb, line 60
    60:     def dataset_need_primary_key?
    61:       true
    62:     end

eager_graph_lazy_dataset?()

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

[Source]

        # File lib/sequel_model/association_reflection.rb, line 65
    65:     def eager_graph_lazy_dataset?
    66:       true
    67:     end

need_associated_primary_key?()

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

[Source]

        # File lib/sequel_model/association_reflection.rb, line 71
    71:     def need_associated_primary_key?
    72:       false
    73:     end

reciprocal()

Returns/sets the reciprocal association variable, if one exists

[Source]

        # File lib/sequel_model/association_reflection.rb, line 76
    76:     def reciprocal
    77:       return self[:reciprocal] if include?(:reciprocal)
    78:       r_type = reciprocal_type
    79:       key = self[:key]
    80:       associated_class.all_association_reflections.each do |assoc_reflect|
    81:         if assoc_reflect[:type] == r_type && assoc_reflect[:key] == key
    82:           return self[:reciprocal] = assoc_reflect[:name]
    83:         end
    84:       end
    85:       self[:reciprocal] = nil
    86:     end

reciprocal_array?()

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

[Source]

        # File lib/sequel_model/association_reflection.rb, line 90
    90:     def reciprocal_array?
    91:       true
    92:     end

remove_all_method()

Name symbol for remove_all_ association method

[Source]

        # File lib/sequel_model/association_reflection.rb, line 95
    95:     def remove_all_method
    96:
    97:       "remove_all_#{self[:name]}"
    98:     end

remove_method()

Name symbol for remove_ association method

[Source]

         # File lib/sequel_model/association_reflection.rb, line 100
    100:     def remove_method
    101:
    102:       "remove_#{self[:name].to_s.singularize}"
    103:     end

returns_array?()

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

[Source]

         # File lib/sequel_model/association_reflection.rb, line 106
    106:     def returns_array?
    107:       true
    108:     end

select()

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

[Source]

         # File lib/sequel_model/association_reflection.rb, line 111
    111:     def select
    112:       self[:select]
    113:     end

set_reciprocal_to_self?()

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

[Source]

         # File lib/sequel_model/association_reflection.rb, line 116
    116:     def set_reciprocal_to_self?
    117:       false
    118:     end

setter_method()

Name symbol for setter association method

[Source]

         # File lib/sequel_model/association_reflection.rb, line 121
    121:     def setter_method
    122:
    123:       "#{self[:name]}="
    124:     end

[Validate]