Module: Ardm::ActiveRecord::Relation
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/ardm/active_record/relation.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *a, &b) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/ardm/active_record/relation.rb', line 65
def method_missing(meth, *a, &b)
if a.empty? && association = reflect_on_association(meth.to_sym)
case association.macro
when :belongs_to
association.klass.where(klass.primary_key => self.select(association.foreign_key))
when :has_many, :has_one
association.klass.where(association.foreign_key => self.clone)
end
else
super
end
end
|
Instance Method Details
#all(options = {}) ⇒ Object
47
48
49
|
# File 'lib/ardm/active_record/relation.rb', line 47
def all(options={})
apply_finder_options(options)
end
|
#apply_finder_options(options) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/ardm/active_record/relation.rb', line 51
def apply_finder_options(options)
return super if options.nil? || options.empty?
options = options.dup
conditions = options.slice!(*::ActiveRecord::SpawnMethods::VALID_FIND_OPTIONS)
super(options).where(conditions)
end
|
#calculate(operation, column_name, options = {}) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/ardm/active_record/relation.rb', line 58
def calculate(operation, column_name, options={})
if property = properties[column_name]
column_name = property.field
end
super(operation, column_name, options)
end
|
#destroy! ⇒ Object
78
79
80
|
# File 'lib/ardm/active_record/relation.rb', line 78
def destroy!
delete_all
end
|