Class: PassiveRecord::Associations::HasManyRelation
Instance Attribute Summary
Attributes inherited from Relation
#association, #parent_model
Instance Method Summary
collapse
#average, #mode, #pluck, #sum
#child_class, #child_class_name, #create, #id, #lookup, #lookup_or_create, #parent_model_id_field
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/passive_record/associations/has_many.rb', line 42
def method_missing(meth,*args,&blk)
if child_class.methods.include?(meth)
where.send(meth,*args,&blk)
else
super(meth,*args,&blk)
end
end
|
Instance Method Details
#<<(child) ⇒ Object
33
34
35
36
|
# File 'lib/passive_record/associations/has_many.rb', line 33
def <<(child)
child.send(parent_model_id_field + "=", parent_model.id)
all
end
|
#all ⇒ Object
23
24
25
|
# File 'lib/passive_record/associations/has_many.rb', line 23
def all
child_class.where(parent_model_id_field => parent_model.id).all
end
|
#singular? ⇒ Boolean
38
39
40
|
# File 'lib/passive_record/associations/has_many.rb', line 38
def singular?
false
end
|
#where(conditions = {}) ⇒ Object
29
30
31
|
# File 'lib/passive_record/associations/has_many.rb', line 29
def where(conditions={})
child_class.where(conditions.merge(parent_model_id_field.to_sym => parent_model.id))
end
|