Class: MongoMapper::Plugins::Associations::ManyDocumentsProxy
Instance Attribute Summary
Attributes inherited from Proxy
#association, #owner, #target
Instance Method Summary
collapse
#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::Support::Find
Instance Method Details
#<<(*docs) ⇒ Object
Also known as:
push, concat
44
45
46
47
48
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 44
def <<(*docs)
ensure_owner_saved
flatten_deeper(docs).each { |doc| apply_scope(doc).save }
reset
end
|
#all(options = {}) ⇒ Object
21
22
23
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 21
def all(options={})
klass.all(scoped_options(options))
end
|
#build(attrs = {}) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 52
def build(attrs={})
doc = klass.new(attrs)
apply_scope(doc)
reset
doc
end
|
#count(options = {}) ⇒ Object
33
34
35
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 33
def count(options={})
klass.count(scoped_options(options))
end
|
#create(attrs = {}) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 59
def create(attrs={})
doc = klass.new(attrs)
apply_scope(doc).save
reset
doc
end
|
#create!(attrs = {}) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 66
def create!(attrs={})
doc = klass.new(attrs)
apply_scope(doc).save!
reset
doc
end
|
#delete_all(options = {}) ⇒ Object
78
79
80
81
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 78
def delete_all(options={})
klass.delete_all(options.merge(scoped_conditions))
reset
end
|
#destroy_all(options = {}) ⇒ Object
73
74
75
76
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 73
def destroy_all(options={})
all(options).map(&:destroy)
reset
end
|
#find(*args) ⇒ Object
7
8
9
10
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 7
def find(*args)
options = args.
klass.find(*args << scoped_options(options))
end
|
#find!(*args) ⇒ Object
12
13
14
15
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 12
def find!(*args)
options = args.
klass.find!(*args << scoped_options(options))
end
|
#first(options = {}) ⇒ Object
25
26
27
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 25
def first(options={})
klass.first(scoped_options(options))
end
|
#last(options = {}) ⇒ Object
29
30
31
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 29
def last(options={})
klass.last(scoped_options(options))
end
|
83
84
85
86
87
88
89
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 83
def nullify
criteria = Query.new(klass, scoped_conditions).criteria
all(criteria).each do |doc|
doc.update_attributes(self.foreign_key => nil)
end
reset
end
|
#paginate(options) ⇒ Object
17
18
19
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 17
def paginate(options)
klass.paginate(scoped_options(options))
end
|
#replace(docs) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/mongo_mapper/plugins/associations/many_documents_proxy.rb', line 37
def replace(docs)
load_target
target.map(&:destroy)
docs.each { |doc| apply_scope(doc).save }
reset
end
|