Class: MongoMapper::Plugins::Associations::ManyDocumentsProxy
- Inherits:
-
Collection
show all
- Includes:
- Finders
- Defined in:
- lib/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb
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
44
45
46
47
48
|
# File 'lib/novelys_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/novelys_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
|
# File 'lib/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb', line 52
def build(attrs={})
doc = klass.new(attrs)
apply_scope(doc)
doc
end
|
#count(options = {}) ⇒ Object
33
34
35
|
# File 'lib/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb', line 33
def count(options={})
klass.count(scoped_options(options))
end
|
#create(attrs = {}) ⇒ Object
58
59
60
61
62
|
# File 'lib/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb', line 58
def create(attrs={})
doc = klass.new(attrs)
apply_scope(doc).save
doc
end
|
#create!(attrs = {}) ⇒ Object
64
65
66
67
68
|
# File 'lib/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb', line 64
def create!(attrs={})
doc = klass.new(attrs)
apply_scope(doc).save!
doc
end
|
#delete_all(options = {}) ⇒ Object
75
76
77
78
|
# File 'lib/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb', line 75
def delete_all(options={})
klass.delete_all(options.merge(scoped_conditions))
reset
end
|
#destroy_all(options = {}) ⇒ Object
70
71
72
73
|
# File 'lib/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb', line 70
def destroy_all(options={})
all(options).map(&:destroy)
reset
end
|
#find(*args) ⇒ Object
7
8
9
10
|
# File 'lib/novelys_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/novelys_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/novelys_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/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb', line 29
def last(options={})
klass.last(scoped_options(options))
end
|
80
81
82
83
84
85
86
|
# File 'lib/novelys_mongo_mapper/plugins/associations/many_documents_proxy.rb', line 80
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
17
18
19
|
# File 'lib/novelys_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/novelys_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
|