Class: RPCMapper::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.
242
243
244
|
# File 'lib/rpc_mapper/association.rb', line 242
def proxy_association
@proxy_association
end
|
#target_association ⇒ Object
Returns the value of attribute target_association.
243
244
245
|
# File 'lib/rpc_mapper/association.rb', line 243
def target_association
@target_association
end
|
Instance Method Details
#polymorphic? ⇒ Boolean
323
324
325
|
# File 'lib/rpc_mapper/association.rb', line 323
def polymorphic?
false
end
|
#scope(object) ⇒ Object
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
# File 'lib/rpc_mapper/association.rb', line 266
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 => proxy_ids.call }
end
)
end
if target_association.polymorphic? && target_is_has?
relation = relation.where(
target_association.polymorphic_type =>
RPCMapper::Base.base_class_name(proxy_association.target_klass(object))
)
end
relation
end
|
#target_is_has? ⇒ Boolean
315
316
317
|
# File 'lib/rpc_mapper/association.rb', line 315
def target_is_has?
target_association.is_a?(Has)
end
|
#target_klass ⇒ Object
307
308
309
|
# File 'lib/rpc_mapper/association.rb', line 307
def target_klass
target_association.target_klass(options[:source_type])
end
|
#target_type ⇒ Object
311
312
313
|
# File 'lib/rpc_mapper/association.rb', line 311
def target_type
target_association.type
end
|
#type ⇒ Object
319
320
321
|
# File 'lib/rpc_mapper/association.rb', line 319
def type
:has_many_through
end
|