Parent

Included Modules

Class Index [+]

Quicksearch

Sequel::Model::Associations::AssociationReflection

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.

Public Instance Methods

_add_method() click to toggle source

Name symbol for the _add internal association method

    # File lib/sequel/model/associations.rb, line 21
21:         def _add_method
22:           :"_add_#{singularize(self[:name])}"
23:         end
_dataset_method() click to toggle source

Name symbol for the _dataset association method

    # File lib/sequel/model/associations.rb, line 26
26:         def _dataset_method
27:           :"_#{self[:name]}_dataset"
28:         end
_remove_all_method() click to toggle source

Name symbol for the _remove_all internal association method

    # File lib/sequel/model/associations.rb, line 31
31:         def _remove_all_method
32:           :"_remove_all_#{self[:name]}"
33:         end
_remove_method() click to toggle source

Name symbol for the _remove internal association method

    # File lib/sequel/model/associations.rb, line 36
36:         def _remove_method
37:           :"_remove_#{singularize(self[:name])}"
38:         end
_setter_method() click to toggle source

Name symbol for the _setter association method

    # File lib/sequel/model/associations.rb, line 41
41:         def _setter_method
42:           :"_#{self[:name]}="
43:         end
add_method() click to toggle source

Name symbol for the add association method

    # File lib/sequel/model/associations.rb, line 46
46:         def add_method
47:           :"add_#{singularize(self[:name])}"
48:         end
associated_class() click to toggle source

The class associated to the current model class via this association

    # File lib/sequel/model/associations.rb, line 56
56:         def associated_class
57:           cached_fetch(:class){constantize(self[:class_name])}
58:         end
association_method() click to toggle source

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
can_have_associated_objects?(obj) click to toggle source

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
dataset_helper_method() click to toggle source

Name symbol for the _helper internal association method

    # File lib/sequel/model/associations.rb, line 73
73:         def dataset_helper_method
74:           :"_#{self[:name]}_dataset_helper"
75:         end
dataset_method() click to toggle source

Name symbol for the dataset association method

    # File lib/sequel/model/associations.rb, line 68
68:         def dataset_method
69:           :"#{self[:name]}_dataset"
70:         end
dataset_need_primary_key?() click to toggle source

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
eager_graph_lazy_dataset?() click to toggle source

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
eager_limit_strategy() click to toggle source

The eager limit strategy to use for this dataset.

     # File lib/sequel/model/associations.rb, line 83
 83:         def eager_limit_strategy
 84:           cached_fetch(:_eager_limit_strategy) do
 85:             if self[:limit]
 86:               case s = cached_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
eager_loading_use_associated_key?() click to toggle source

By default associations do not need to select a key in an associated table to eagerly load.

     # File lib/sequel/model/associations.rb, line 105
105:         def eager_loading_use_associated_key?
106:           false
107:         end
limit_and_offset() click to toggle source

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
need_associated_primary_key?() click to toggle source

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(table, col) click to toggle source

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_assoc(col) click to toggle source

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_cur(col) click to toggle source

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
reciprocal() click to toggle source

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:           cached_fetch(:reciprocal) do
155:             r_types = Array(reciprocal_type)
156:             keys = self[:keys]
157:             recip = nil
158:             associated_class.all_association_reflections.each do |assoc_reflect|
159:               if r_types.include?(assoc_reflect[:type]) && assoc_reflect[:keys] == keys && assoc_reflect.associated_class == self[:model]
160:                 cached_set(:reciprocal_type, assoc_reflect[:type])
161:                 recip = assoc_reflect[:name]
162:                 break
163:               end
164:             end
165:             recip
166:           end
167:         end
reciprocal_array?() click to toggle source

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 171
171:         def reciprocal_array?
172:           true
173:         end
remove_all_method() click to toggle source

Name symbol for the remove_all_ association method

     # File lib/sequel/model/associations.rb, line 176
176:         def remove_all_method
177:           :"remove_all_#{self[:name]}"
178:         end
remove_before_destroy?() click to toggle source

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 182
182:         def remove_before_destroy?
183:           true
184:         end
remove_method() click to toggle source

Name symbol for the remove_ association method

     # File lib/sequel/model/associations.rb, line 187
187:         def remove_method
188:           :"remove_#{singularize(self[:name])}"
189:         end
remove_should_check_existing?() click to toggle source

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 192
192:         def remove_should_check_existing?
193:           false
194:         end
returns_array?() click to toggle source

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

     # File lib/sequel/model/associations.rb, line 198
198:         def returns_array?
199:           true
200:         end
select() click to toggle source

The columns to select when loading the association.

     # File lib/sequel/model/associations.rb, line 203
203:         def select
204:           self[:select]
205:         end
set_reciprocal_to_self?() click to toggle source

Whether to set the reciprocal association to self when loading associated records, false by default.

     # File lib/sequel/model/associations.rb, line 209
209:         def set_reciprocal_to_self?
210:           false
211:         end
setter_method() click to toggle source

Name symbol for the setter association method

     # File lib/sequel/model/associations.rb, line 214
214:         def setter_method
215:           :"#{self[:name]}="
216:         end

Private Instance Methods

cached_fetch(key) click to toggle source

On MRI, use a plain fetch, since the GVL will synchronize access.

     # File lib/sequel/model/associations.rb, line 239
239:           def cached_fetch(key)
240:             fetch(key) do 
241:               h = self[:cache]
242:               h.fetch(key){h[key] = yield}
243:             end
244:           end
cached_fetch(key) click to toggle source

On non-GVL rubies, assume the need to synchronize access. Store the key in a special sub-hash that always uses this method to synchronize access.

     # File lib/sequel/model/associations.rb, line 223
223:           def cached_fetch(key)
224:             fetch(key) do
225:               h = self[:cache]
226:               Sequel.synchronize{return h[key] if h.has_key?(key)}
227:               value = yield
228:               Sequel.synchronize{h[key] = value}
229:             end
230:           end
cached_set(key, value) click to toggle source

On MRI, just set the value at the key in the cache, since the GVL will synchronize access.

     # File lib/sequel/model/associations.rb, line 248
248:           def cached_set(key, value)
249:             self[:cache][key] = value
250:           end
cached_set(key, value) click to toggle source

Cache the value at the given key, synchronizing access.

     # File lib/sequel/model/associations.rb, line 233
233:           def cached_set(key, value)
234:             h = self[:cache]
235:             Sequel.synchronize{h[key] = value}
236:           end
transform(s) click to toggle source

If s is an array, map s over the block. Otherwise, just call the block with s.

     # File lib/sequel/model/associations.rb, line 255
255:         def transform(s)
256:           s.is_a?(Array) ? s.map(&Proc.new) : (yield s)
257:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.