Class: Perry::Association::HasManyThrough
Instance Attribute Summary collapse
Attributes inherited from Base
#id, #options, #source_klass
Instance Method Summary
collapse
Methods inherited from HasMany
#collection?
Methods inherited from Has
#foreign_key, #polymorphic_type
Methods inherited from Base
#collection?, #eager_loadable?, #foreign_key, #initialize, #primary_key
Instance Attribute Details
#proxy_association ⇒ Object
Returns the value of attribute proxy_association.
271
272
273
|
# File 'lib/perry/association.rb', line 271
def proxy_association
@proxy_association
end
|
#target_association ⇒ Object
Returns the value of attribute target_association.
272
273
274
|
# File 'lib/perry/association.rb', line 272
def target_association
@target_association
end
|
Instance Method Details
#polymorphic? ⇒ Boolean
352
353
354
|
# File 'lib/perry/association.rb', line 352
def polymorphic?
false
end
|
#scope(object) ⇒ Object
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/perry/association.rb', line 295
def scope(object)
key = if target_is_has?
target_association.primary_key.to_sym
else
target_association.foreign_key.to_sym
end
proxy_ids = proc do
proxy_association.scope(object).select(key).collect(&key)
end
relation = target_klass.scoped
if target_is_has?
relation = relation.where(
proc do
{ target_association.foreign_key => proxy_ids.call }
end
)
else
relation = relation.where(
proc do
{ target_association.primary_key(options[:source_type]) => proxy_ids.call }
end
)
end
if target_association.polymorphic? && target_is_has?
relation = relation.where(
target_association.polymorphic_type =>
Perry::Base.base_class_name(proxy_association.target_klass(object))
)
end
relation
end
|
#target_is_has? ⇒ Boolean
344
345
346
|
# File 'lib/perry/association.rb', line 344
def target_is_has?
target_association.is_a?(Has)
end
|
#target_klass ⇒ Object
336
337
338
|
# File 'lib/perry/association.rb', line 336
def target_klass
target_association.target_klass(options[:source_type])
end
|
#target_type ⇒ Object
340
341
342
|
# File 'lib/perry/association.rb', line 340
def target_type
target_association.type
end
|
#type ⇒ Object
348
349
350
|
# File 'lib/perry/association.rb', line 348
def type
:has_many_through
end
|