Class: PassiveRecord::Associations::HasManyRelation

Inherits:
HasOneRelation show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/passive_record/associations/has_many.rb

Direct Known Subclasses

HasManyThroughRelation

Instance Attribute Summary

Attributes inherited from Relation

#association, #parent_model

Instance Method Summary collapse

Methods inherited from HasOneRelation

#child_class, #create, #id, #lookup, #parent_class_name, #parent_model_id_field

Instance Method Details

#<<(child) ⇒ Object



34
35
36
37
# File 'lib/passive_record/associations/has_many.rb', line 34

def <<(child)
  child.send(parent_model_id_field + "=", parent_model.id)
  all
end

#allObject



17
18
19
# File 'lib/passive_record/associations/has_many.rb', line 17

def all
  child_class.where(parent_model_id_field => parent_model.id).all
end

#all?(*args) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/passive_record/associations/has_many.rb', line 22

def all?(*args)
  all.all?(*args)
end

#empty?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/passive_record/associations/has_many.rb', line 26

def empty?
  all.empty?
end

#singular?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/passive_record/associations/has_many.rb', line 39

def singular?
  false
end

#where(conditions = {}) ⇒ Object



30
31
32
# File 'lib/passive_record/associations/has_many.rb', line 30

def where(conditions={})
  child_class.where(conditions.merge(parent_model_id_field.to_sym => parent_model.id))
end