Class: ActiveAny::Associations::HasManyAssociation
- Inherits:
-
Association
- Object
- Association
- ActiveAny::Associations::HasManyAssociation
show all
- Defined in:
- lib/active_any/associations/has_many_association.rb
Instance Attribute Summary
Attributes inherited from Association
#inversed, #loaded, #owner, #reflection, #target
Instance Method Summary
collapse
Methods inherited from Association
#association_scope, #find_from_target?, #initialize, #klass, #load_target, #loaded!, #loaded?, #reload, #reset_scope, #scope, #set_inverse_instance, #target_scope
Instance Method Details
#empty? ⇒ Boolean
31
32
33
|
# File 'lib/active_any/associations/has_many_association.rb', line 31
def empty?
size.zero?
end
|
#find_target ⇒ Object
43
44
45
|
# File 'lib/active_any/associations/has_many_association.rb', line 43
def find_target
scope.to_a
end
|
#include?(record) ⇒ Boolean
35
36
37
38
39
40
41
|
# File 'lib/active_any/associations/has_many_association.rb', line 35
def include?(record)
if record.is_a?(klass)
target.include?(record)
else
false
end
end
|
6
7
8
9
10
11
12
|
# File 'lib/active_any/associations/has_many_association.rb', line 6
def reader
@proxy ||= CollectionProxy.create(owner, self)
@proxy.reset_scope
end
|
18
19
20
21
|
# File 'lib/active_any/associations/has_many_association.rb', line 18
def reset
super
@target = []
end
|
23
24
25
26
27
28
29
|
# File 'lib/active_any/associations/has_many_association.rb', line 23
def size
if !find_target? || loaded?
target.size
else
scope.count
end
end
|
#writer(_records) ⇒ Object
14
15
16
|
# File 'lib/active_any/associations/has_many_association.rb', line 14
def writer(_records)
raise NotImplementedError.new, 'writer is unimplemented'
end
|