Class: MongoMapper::Associations::ManyDocumentsProxy
Instance Attribute Summary
Attributes inherited from Proxy
#owner, #reflection, #target
Instance Method Summary
collapse
Methods included from Finders
#dynamic_find
Methods inherited from Collection
#reset, #to_ary
Methods inherited from Proxy
#===, #blank?, #initialize, #inspect, #loaded, #loaded?, #nil?, #present?, #proxy_respond_to?, #reload, #reset, #respond_to?, #send
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class MongoMapper::Finders
Instance Method Details
#<<(*docs) ⇒ Object
Also known as:
push, concat
43
44
45
46
47
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 43
def <<(*docs)
ensure_owner_saved
flatten_deeper(docs).each { |doc| apply_scope(doc).save }
reset
end
|
#all(options = {}) ⇒ Object
20
21
22
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 20
def all(options={})
klass.all(scoped_options(options))
end
|
#build(attrs = {}) ⇒ Object
51
52
53
54
55
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 51
def build(attrs={})
doc = klass.new(attrs)
apply_scope(doc)
doc
end
|
#count(options = {}) ⇒ Object
32
33
34
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 32
def count(options={})
klass.count(scoped_options(options))
end
|
#create(attrs = {}) ⇒ Object
57
58
59
60
61
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 57
def create(attrs={})
doc = klass.new(attrs)
apply_scope(doc).save
doc
end
|
#create!(attrs = {}) ⇒ Object
63
64
65
66
67
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 63
def create!(attrs={})
doc = klass.new(attrs)
apply_scope(doc).save!
doc
end
|
#delete_all(options = {}) ⇒ Object
74
75
76
77
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 74
def delete_all(options={})
klass.delete_all(options.merge(scoped_conditions))
reset
end
|
#destroy_all(options = {}) ⇒ Object
69
70
71
72
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 69
def destroy_all(options={})
all(options).map(&:destroy)
reset
end
|
#find(*args) ⇒ Object
6
7
8
9
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 6
def find(*args)
options = args.
klass.find(*args << scoped_options(options))
end
|
#find!(*args) ⇒ Object
11
12
13
14
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 11
def find!(*args)
options = args.
klass.find!(*args << scoped_options(options))
end
|
#first(options = {}) ⇒ Object
24
25
26
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 24
def first(options={})
klass.first(scoped_options(options))
end
|
#last(options = {}) ⇒ Object
28
29
30
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 28
def last(options={})
klass.last(scoped_options(options))
end
|
79
80
81
82
83
84
85
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 79
def nullify
criteria = FinderOptions.new(klass, scoped_conditions).criteria
all(criteria).each do |doc|
doc.update_attributes(self.foreign_key => nil)
end
reset
end
|
#paginate(options) ⇒ Object
16
17
18
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 16
def paginate(options)
klass.paginate(scoped_options(options))
end
|
#replace(docs) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 36
def replace(docs)
load_target
target.map(&:destroy)
docs.each { |doc| apply_scope(doc).save }
reset
end
|