Class: NinjaModel::Associations::HasManyAssociation
- Inherits:
-
Object
- Object
- NinjaModel::Associations::HasManyAssociation
show all
- Defined in:
- lib/ninja_model/associations/has_many_association.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of HasManyAssociation.
4
5
6
7
|
# File 'lib/ninja_model/associations/has_many_association.rb', line 4
def initialize(owner, reflection)
@owner, @reflection = owner, reflection
@relation = reflection.klass.scoped.where(reflection.primary_key_name.to_sym.eq(owner.id))
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/ninja_model/associations/has_many_association.rb', line 11
def method_missing(method, *args)
if @relation.respond_to?(method)
@relation.send(method, *args)
else
super
end
end
|
Instance Method Details
#blank? ⇒ Boolean
31
32
33
|
# File 'lib/ninja_model/associations/has_many_association.rb', line 31
def blank?
@relation.blank?
end
|
#inspect ⇒ Object
23
24
25
|
# File 'lib/ninja_model/associations/has_many_association.rb', line 23
def inspect
@relation.to_a.inspect
end
|
#relation ⇒ Object
19
20
21
|
# File 'lib/ninja_model/associations/has_many_association.rb', line 19
def relation
@relation
end
|
#replace(other_array) ⇒ Object
27
28
29
|
# File 'lib/ninja_model/associations/has_many_association.rb', line 27
def replace(other_array)
@current = other_array
end
|
#to_ary ⇒ Object
35
36
37
|
# File 'lib/ninja_model/associations/has_many_association.rb', line 35
def to_ary
@relation.to_a
end
|