mongoid-pre 2.0.0.beta1 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.watchr +15 -10
- data/HISTORY +342 -0
- data/README.rdoc +8 -1
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/lib/mongoid/associations/{embedded_in.rb → belongs_to.rb} +4 -4
- data/lib/mongoid/associations/belongs_to_related.rb +9 -6
- data/lib/mongoid/associations/{embeds_many.rb → has_many.rb} +20 -33
- data/lib/mongoid/associations/has_many_related.rb +4 -28
- data/lib/mongoid/associations/{embeds_one.rb → has_one.rb} +6 -6
- data/lib/mongoid/associations/options.rb +6 -1
- data/lib/mongoid/associations.rb +32 -41
- data/lib/mongoid/attributes.rb +6 -13
- data/lib/mongoid/collection.rb +1 -2
- data/lib/mongoid/commands/delete.rb +1 -1
- data/lib/mongoid/commands/delete_all.rb +1 -4
- data/lib/mongoid/commands/destroy.rb +1 -1
- data/lib/mongoid/commands/destroy_all.rb +1 -3
- data/lib/mongoid/commands/save.rb +0 -1
- data/lib/mongoid/commands.rb +13 -2
- data/lib/mongoid/components.rb +1 -6
- data/lib/mongoid/config.rb +1 -5
- data/lib/mongoid/contexts/enumerable.rb +17 -54
- data/lib/mongoid/contexts/mongo.rb +38 -101
- data/lib/mongoid/contexts/paging.rb +2 -2
- data/lib/mongoid/contexts.rb +0 -21
- data/lib/mongoid/criteria.rb +73 -15
- data/lib/mongoid/criterion/inclusion.rb +0 -2
- data/lib/mongoid/criterion/optional.rb +2 -10
- data/lib/mongoid/document.rb +30 -41
- data/lib/mongoid/extensions.rb +0 -15
- data/lib/mongoid/field.rb +7 -20
- data/lib/mongoid/fields.rb +10 -15
- data/lib/mongoid/finders.rb +98 -10
- data/lib/mongoid/identity.rb +2 -8
- data/lib/mongoid/named_scope.rb +0 -2
- data/lib/mongoid/validations/associated.rb +8 -3
- data/lib/mongoid/validations/uniqueness.rb +7 -2
- data/lib/mongoid/validations.rb +2 -2
- data/lib/mongoid/versioning.rb +1 -1
- data/lib/mongoid.rb +5 -21
- data/mongoid.gemspec +19 -59
- data/spec/integration/mongoid/associations_spec.rb +3 -42
- data/spec/integration/mongoid/attributes_spec.rb +2 -2
- data/spec/integration/mongoid/commands_spec.rb +13 -27
- data/spec/integration/mongoid/contexts/enumerable_spec.rb +0 -13
- data/spec/integration/mongoid/criteria_spec.rb +3 -50
- data/spec/integration/mongoid/document_spec.rb +5 -72
- data/spec/integration/mongoid/finders_spec.rb +28 -85
- data/spec/models/address.rb +3 -3
- data/spec/models/animal.rb +2 -2
- data/spec/models/country_code.rb +2 -2
- data/spec/models/game.rb +1 -2
- data/spec/models/inheritance.rb +5 -5
- data/spec/models/location.rb +2 -2
- data/spec/models/name.rb +3 -3
- data/spec/models/namespacing.rb +2 -2
- data/spec/models/patient.rb +0 -2
- data/spec/models/person.rb +4 -6
- data/spec/models/pet.rb +3 -3
- data/spec/models/pet_owner.rb +3 -3
- data/spec/models/phone.rb +3 -3
- data/spec/models/post.rb +1 -1
- data/spec/models/translation.rb +2 -2
- data/spec/models/vet_visit.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +0 -4
- data/spec/unit/mongoid/associations/{embedded_in_spec.rb → belongs_to_spec.rb} +11 -11
- data/spec/unit/mongoid/associations/has_many_related_spec.rb +14 -45
- data/spec/unit/mongoid/associations/{embeds_many_spec.rb → has_many_spec.rb} +34 -79
- data/spec/unit/mongoid/associations/{embeds_one_spec.rb → has_one_spec.rb} +18 -18
- data/spec/unit/mongoid/associations/options_spec.rb +19 -20
- data/spec/unit/mongoid/associations_spec.rb +12 -74
- data/spec/unit/mongoid/attributes_spec.rb +51 -83
- data/spec/unit/mongoid/collection_spec.rb +0 -46
- data/spec/unit/mongoid/commands/delete_all_spec.rb +8 -9
- data/spec/unit/mongoid/commands/delete_spec.rb +3 -6
- data/spec/unit/mongoid/commands/destroy_all_spec.rb +2 -0
- data/spec/unit/mongoid/commands/destroy_spec.rb +3 -10
- data/spec/unit/mongoid/commands_spec.rb +11 -20
- data/spec/unit/mongoid/config_spec.rb +0 -18
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +11 -198
- data/spec/unit/mongoid/contexts/mongo_spec.rb +54 -357
- data/spec/unit/mongoid/criteria_spec.rb +78 -107
- data/spec/unit/mongoid/criterion/exclusion_spec.rb +13 -3
- data/spec/unit/mongoid/criterion/inclusion_spec.rb +19 -25
- data/spec/unit/mongoid/criterion/optional_spec.rb +18 -25
- data/spec/unit/mongoid/document_spec.rb +34 -71
- data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
- data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +3 -0
- data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -16
- data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
- data/spec/unit/mongoid/field_spec.rb +0 -62
- data/spec/unit/mongoid/fields_spec.rb +0 -33
- data/spec/unit/mongoid/finders_spec.rb +1 -37
- data/spec/unit/mongoid/identity_spec.rb +6 -47
- data/spec/unit/mongoid/named_scope_spec.rb +2 -15
- data/spec/unit/mongoid/scope_spec.rb +1 -1
- data/spec/unit/mongoid/validations/uniqueness_spec.rb +3 -3
- data/spec/unit/mongoid_spec.rb +2 -11
- metadata +14 -64
- data/lib/mongoid/associations/meta_data.rb +0 -28
- data/lib/mongoid/contexts/ids.rb +0 -25
- data/lib/mongoid/deprecation.rb +0 -22
- data/lib/mongoid/dirty.rb +0 -203
- data/lib/mongoid/extensions/big_decimal/conversions.rb +0 -19
- data/lib/mongoid/extensions/binary/conversions.rb +0 -17
- data/lib/mongoid/extensions/objectid/conversions.rb +0 -15
- data/lib/mongoid/extras.rb +0 -61
- data/lib/mongoid/javascript/functions.yml +0 -37
- data/lib/mongoid/javascript.rb +0 -21
- data/lib/mongoid/observable.rb +0 -30
- data/lib/mongoid/paths.rb +0 -54
- data/lib/mongoid/persistence/command.rb +0 -20
- data/lib/mongoid/persistence/insert.rb +0 -71
- data/lib/mongoid/persistence/update.rb +0 -78
- data/lib/mongoid/persistence.rb +0 -27
- data/lib/mongoid/state.rb +0 -32
- data/spec/integration/mongoid/dirty_spec.rb +0 -70
- data/spec/integration/mongoid/persistence/update_spec.rb +0 -46
- data/spec/models/callbacks.rb +0 -18
- data/spec/unit/mongoid/associations/meta_data_spec.rb +0 -88
- data/spec/unit/mongoid/contexts_spec.rb +0 -25
- data/spec/unit/mongoid/deprecation_spec.rb +0 -24
- data/spec/unit/mongoid/dirty_spec.rb +0 -286
- data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extras_spec.rb +0 -102
- data/spec/unit/mongoid/javascript_spec.rb +0 -48
- data/spec/unit/mongoid/observable_spec.rb +0 -46
- data/spec/unit/mongoid/paths_spec.rb +0 -124
- data/spec/unit/mongoid/persistence/insert_spec.rb +0 -175
- data/spec/unit/mongoid/persistence/update_spec.rb +0 -148
- data/spec/unit/mongoid/persistence_spec.rb +0 -40
- data/spec/unit/mongoid/state_spec.rb +0 -83
data/.watchr
CHANGED
@@ -1,24 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# Watchr is the preferred method to run specs automatically over rspactor for
|
2
|
+
# Mongoid. If you are using vim, you can add the file:
|
3
|
+
#
|
4
|
+
# ~/.vim/ftdetect/watchr.vim
|
5
|
+
#
|
6
|
+
# This should have only the following line in it:
|
7
|
+
#
|
8
|
+
# autocmd BufNewFile,BufRead *.watchr setf ruby
|
9
|
+
#
|
10
|
+
# This will enable vim to recognize this file as ruby code should you wish to
|
11
|
+
# edit it.
|
2
12
|
def run(cmd)
|
3
13
|
puts cmd
|
4
14
|
system cmd
|
5
15
|
end
|
6
16
|
|
7
17
|
def spec(file)
|
8
|
-
|
9
|
-
run("spec -O spec/spec.opts #{file}")
|
10
|
-
else
|
11
|
-
puts("Spec: #{file} does not exist.")
|
12
|
-
end
|
18
|
+
run "spec -O spec/spec.opts #{file}"
|
13
19
|
end
|
14
20
|
|
15
21
|
watch("spec/.*/*_spec\.rb") do |match|
|
16
|
-
|
22
|
+
p match[0]
|
17
23
|
spec(match[0])
|
18
24
|
end
|
19
25
|
|
20
|
-
watch(
|
21
|
-
|
26
|
+
watch('lib/(.*/.*)\.rb') do |match|
|
27
|
+
p match[1]
|
22
28
|
spec("spec/unit/#{match[1]}_spec.rb")
|
23
|
-
spec("spec/integration/#{match[1]}_spec.rb")
|
24
29
|
end
|
data/HISTORY
ADDED
@@ -0,0 +1,342 @@
|
|
1
|
+
=== 1.2.0
|
2
|
+
- Fixed composite key generation not to replace all
|
3
|
+
special chars with dashes.
|
4
|
+
|
5
|
+
- Memory optimizations, now wrapping the mongo cursor.
|
6
|
+
|
7
|
+
- Fixed memoization on has_many_related assocations.
|
8
|
+
|
9
|
+
- Fixed pagination on embedded associations
|
10
|
+
|
11
|
+
- Fixed after_update callback not getting fired.
|
12
|
+
|
13
|
+
- When a connection failure occurs, Mongoid tried to
|
14
|
+
retry the operation up to a configurable time.
|
15
|
+
|
16
|
+
- Mongoid now supports a configuration with a master
|
17
|
+
and multiple read slaves. It will direct all writes
|
18
|
+
to the master and all reads to the slaves. In the case
|
19
|
+
of a write, subsequent reads will be directed to the
|
20
|
+
master up to configurable number to try and counter
|
21
|
+
the 2 second slave sync delay.
|
22
|
+
|
23
|
+
- Fixed issue with criteria exclusion queries with ids.
|
24
|
+
|
25
|
+
- Mongoid only executes a count when explicitly paginating.
|
26
|
+
|
27
|
+
- Fixed Criteria offset to be a getter or setter
|
28
|
+
|
29
|
+
- Added indexes to foreign keys on belongs_to_related
|
30
|
+
associations.
|
31
|
+
|
32
|
+
- General code refactorings/cleanup
|
33
|
+
|
34
|
+
=== 1.1.4
|
35
|
+
- Refactorings in preparation for next feature push.
|
36
|
+
|
37
|
+
- Associations may now have anonymous extensions.
|
38
|
+
|
39
|
+
- Ruby 1.9 compatibility updates. (brainopia)
|
40
|
+
|
41
|
+
- Document.to_json accepts options. (jsmestad)
|
42
|
+
|
43
|
+
=== 1.1.3
|
44
|
+
- Nil can be passed into methods that set attributes.
|
45
|
+
|
46
|
+
- Mongoid.config can now take a block.
|
47
|
+
|
48
|
+
- Allow named_scopes and criteria class methods on
|
49
|
+
has_many_related if related is a Mongoid document.
|
50
|
+
|
51
|
+
- Document.find can now take an array of ids.
|
52
|
+
|
53
|
+
=== 1.1.2
|
54
|
+
- Fixing issues with updates to parents.
|
55
|
+
|
56
|
+
=== 1.1.1
|
57
|
+
- Document.create raises validations error, not no
|
58
|
+
method error on self.errors (Rick Frankel)
|
59
|
+
|
60
|
+
- Support default values that respond_to?(:call)
|
61
|
+
(procs/lambda) (ahoward)
|
62
|
+
|
63
|
+
- Added Mongoid.persist_in_safe_mode global config
|
64
|
+
option.
|
65
|
+
|
66
|
+
- Minor optimization: don't evaluate default procs
|
67
|
+
if it's not needed (brainopia)
|
68
|
+
|
69
|
+
=== 1.1.0
|
70
|
+
- Nil attributes no longer persist nil values to the
|
71
|
+
database - the field will just not exist.
|
72
|
+
|
73
|
+
- create! and save! will now properly raise an error
|
74
|
+
when a database operation fails. This is handled
|
75
|
+
by using :safe => true as an option to
|
76
|
+
collection.save.
|
77
|
+
|
78
|
+
- Setting blank numbers casts to nil.
|
79
|
+
|
80
|
+
- Criteria and named scopes can now be used on has
|
81
|
+
many relationships. They can be chained with each
|
82
|
+
other off the association chain.
|
83
|
+
|
84
|
+
- Mongoid can now determine if a document matches a
|
85
|
+
mongodb selector without hitting the database via
|
86
|
+
Document#matches?(selector).
|
87
|
+
|
88
|
+
- Overall performance improvements in all areas.
|
89
|
+
|
90
|
+
- Ruby 1.9 compatibility fixes.
|
91
|
+
|
92
|
+
- Has many related now supports finding by id or
|
93
|
+
by an optional :all, :first, :last with a
|
94
|
+
conditions hash.
|
95
|
+
|
96
|
+
=== 1.0.6
|
97
|
+
|
98
|
+
- Preventing the setting of empty values in attributes.
|
99
|
+
|
100
|
+
- Better inspect formatting
|
101
|
+
|
102
|
+
=== 1.0.5
|
103
|
+
|
104
|
+
- Has one and has many associations now set the parent
|
105
|
+
object first before writing the attributes on
|
106
|
+
#build and #create.
|
107
|
+
|
108
|
+
=== 1.0.4
|
109
|
+
- Modified criteria to use the querying class
|
110
|
+
when instantiating documents if there are no
|
111
|
+
subclasses.
|
112
|
+
|
113
|
+
- Floats that are empty strings or nil get
|
114
|
+
defaulted to 0.0
|
115
|
+
|
116
|
+
=== 1.0.3
|
117
|
+
- Small performance improvements on finders
|
118
|
+
|
119
|
+
- Float.set allows setting of non-numeric string
|
120
|
+
in order for validates_numericality_of to fail
|
121
|
+
properly.
|
122
|
+
|
123
|
+
=== 1.0.2
|
124
|
+
- Named scopes get added functionality:
|
125
|
+
|
126
|
+
- named scopes can now be criteria objects.
|
127
|
+
|
128
|
+
- named scoped can now be procs with criteria.
|
129
|
+
|
130
|
+
- named scopes and class methods that return
|
131
|
+
criteria can be chained with each other.
|
132
|
+
|
133
|
+
- When calling save on an embedded document whose
|
134
|
+
validation passes but the parent's validation
|
135
|
+
fails, it will properly return false.
|
136
|
+
|
137
|
+
=== 1.0.1
|
138
|
+
- Documents now have named_scopes similar to
|
139
|
+
ActiveRecord named scopes. Please see rdoc or
|
140
|
+
specs for examples.
|
141
|
+
|
142
|
+
- Document#to_json properly works in all cases.
|
143
|
+
|
144
|
+
- ActiveSupport calls for inflections have been
|
145
|
+
moved into the String::Inflections module.
|
146
|
+
|
147
|
+
- Updated dependency on Validatable to 2.0.1
|
148
|
+
|
149
|
+
=== 1.0.0
|
150
|
+
- Validations cleanup: Only before_validation and
|
151
|
+
after_validation callbacks are supported now.
|
152
|
+
|
153
|
+
- Dynamic fields have reader and writer methods
|
154
|
+
again, but only for instances where the dynamic
|
155
|
+
attribute exists.
|
156
|
+
|
157
|
+
- Lots of refactoring, mostly coverting common
|
158
|
+
fucntionality into modules for the upcoming rails
|
159
|
+
2 and 3 gem split.
|
160
|
+
|
161
|
+
=== 0.12.0
|
162
|
+
- Has one now works as expected:
|
163
|
+
|
164
|
+
- Has one associations will return nil, instead
|
165
|
+
of the proxy if the association has not been
|
166
|
+
set.
|
167
|
+
|
168
|
+
- Building/creating a has one is no longer handled
|
169
|
+
by calling the Document#association#build() or create(),
|
170
|
+
this is now handled by Document#build_name and
|
171
|
+
Document#create_name where "name" is the name
|
172
|
+
of the has one association.
|
173
|
+
|
174
|
+
- Passing a _type attribute to the #build_name
|
175
|
+
and #create_name methods will build/create
|
176
|
+
objects of that type, useful for creating
|
177
|
+
specific subclasses.
|
178
|
+
|
179
|
+
- The existing #build and #create methods will be
|
180
|
+
removed in the next release.
|
181
|
+
|
182
|
+
- Removed all dynamic finders. If you need to have
|
183
|
+
functionality similar to "find_or_(create|initialize)_by"
|
184
|
+
you can use the 2 new finders:
|
185
|
+
|
186
|
+
- Document.find_or_create_by(attributes): Will
|
187
|
+
look for a document in the database with the
|
188
|
+
supplied attributes, if found it will return the
|
189
|
+
document otherwise will create a new one with
|
190
|
+
the supplied attributes.
|
191
|
+
|
192
|
+
- Document.find_or_initialize_by(attributes): Will
|
193
|
+
look for a document in the database with the
|
194
|
+
supplied attributes, if found it will return the
|
195
|
+
document otherwise will instantiate a new one with
|
196
|
+
the supplied attributes.
|
197
|
+
|
198
|
+
- Fixed issue with empty hashes and arrays not getting
|
199
|
+
set on document instantiation.
|
200
|
+
|
201
|
+
=== 0.11.9
|
202
|
+
- Fixed issue with non-us time zones and formats
|
203
|
+
parsing incorrectly.
|
204
|
+
|
205
|
+
- Fixed error when specifying field restrictions
|
206
|
+
in criteria and not providing the _type. It
|
207
|
+
will now automaticall get added if it is not
|
208
|
+
present.
|
209
|
+
|
210
|
+
- Slight cleanup of delegated methods in Document.
|
211
|
+
|
212
|
+
- Dynamic attributes no longer create setters and
|
213
|
+
getters on the class. They can be accessed from
|
214
|
+
the attributes hash directly. If they are used
|
215
|
+
frequently it is preferrable to just add a field
|
216
|
+
to the class manually.
|
217
|
+
|
218
|
+
- Criteria#min no longer always returns 0.0.
|
219
|
+
|
220
|
+
=== 0.11.8
|
221
|
+
- Added #min and #max to criteria which takes a
|
222
|
+
single field argument.
|
223
|
+
|
224
|
+
=== 0.11.7
|
225
|
+
- Added #sum to criteria which takes a single field
|
226
|
+
to aggregate on. Example: Person.sum(:age) would
|
227
|
+
return a float that was the sum of all people's
|
228
|
+
ages in the db.
|
229
|
+
|
230
|
+
- Fixed issue with queries from parent classes always
|
231
|
+
casting the returned documents to the parent.
|
232
|
+
|
233
|
+
- Fixed singleton require issue.
|
234
|
+
|
235
|
+
- Group queries now run as db commands
|
236
|
+
|
237
|
+
=== 0.11.6
|
238
|
+
- Allow namespaced documents to default with:
|
239
|
+
"namespace_modelname"
|
240
|
+
|
241
|
+
- Fixed indexing of _type field to only happen on root
|
242
|
+
classes.
|
243
|
+
|
244
|
+
- Fixed creation of empty collections for embedded documents.
|
245
|
+
|
246
|
+
- Document.store_in now properly resets the collection
|
247
|
+
if the collection had already been accessed.
|
248
|
+
|
249
|
+
- Document.find(nil) now raises
|
250
|
+
Mongoid::Errors::InvalidOptions
|
251
|
+
|
252
|
+
=== 0.11.5
|
253
|
+
- Removed dependency on mongo_ext, since latest version
|
254
|
+
was breaking on various operating systems.
|
255
|
+
=== 0.11.4
|
256
|
+
- Fixed issue with dynamic fields: checking whether
|
257
|
+
the document responded to the attribute's method
|
258
|
+
should have checked the setter and not the getter
|
259
|
+
|
260
|
+
- Fixed has_one associations not being able to be
|
261
|
+
set to nil.
|
262
|
+
|
263
|
+
=== 0.11.3
|
264
|
+
- Fixed issue with Document#save! not calling before
|
265
|
+
and after create callbacks if document is new
|
266
|
+
|
267
|
+
=== 0.11.2
|
268
|
+
- Fixing bug where has many and has one relational
|
269
|
+
associations create method did not return the
|
270
|
+
associated document
|
271
|
+
|
272
|
+
=== 0.11.1
|
273
|
+
- Querying for classes that have subclasses will also
|
274
|
+
return the subclasses as well, similar to
|
275
|
+
ActiveRecord.
|
276
|
+
|
277
|
+
- Adding configuration option allow_dynamic_fields. This
|
278
|
+
defaults to true and if set to false will raise an
|
279
|
+
error when trying to set an attribute on an object
|
280
|
+
that does not have a corresponding field defined.
|
281
|
+
|
282
|
+
=== 0.11.0
|
283
|
+
- Set the collection name to store a document in via:
|
284
|
+
Document.store_in :collection_name
|
285
|
+
|
286
|
+
- Initial inheritance support:
|
287
|
+
|
288
|
+
- Documents and their associations can now have an
|
289
|
+
infinite number of subclasses.
|
290
|
+
|
291
|
+
- Has many and has one associations can build or
|
292
|
+
create specific subclasses by providing an optional
|
293
|
+
class as the last parameter to the #create and
|
294
|
+
#build methods on the respective associations.
|
295
|
+
|
296
|
+
- Querying for specific subclasses will only return
|
297
|
+
those documents which were saved as that subclass,
|
298
|
+
even though the hierarchy is stored in the same
|
299
|
+
collection.
|
300
|
+
|
301
|
+
- Deletion of subclass documents will only delete
|
302
|
+
documents of that type, even though they all exist
|
303
|
+
in the same collection. #delete_all and #destroy_all
|
304
|
+
also support this behavoir.
|
305
|
+
|
306
|
+
- Updated mongo and mongo_ext dependencies to 0.18.2
|
307
|
+
|
308
|
+
- Fixed save on new documents to return true instead
|
309
|
+
of the document itself.
|
310
|
+
|
311
|
+
=== 0.10.6
|
312
|
+
- Fixed bug when trying to set empty strings on number
|
313
|
+
fields. (TypeError: can't convert Fixnum into String)
|
314
|
+
|
315
|
+
- Document.delete_all now drops the collection if
|
316
|
+
conditions are empty or nil.
|
317
|
+
|
318
|
+
=== 0.10.5
|
319
|
+
|
320
|
+
- Documents that are embedded not properly respond to
|
321
|
+
Document#destroy and Document#delete.
|
322
|
+
|
323
|
+
- Documents can now be saved sans validation with
|
324
|
+
Document#save(false)
|
325
|
+
|
326
|
+
=== 0.10.4
|
327
|
+
|
328
|
+
- Documents no longer inherit from Mongoid::Document.
|
329
|
+
Please include Mongoid::Document in all your models now.
|
330
|
+
|
331
|
+
- Config module added, you can now set one option:
|
332
|
+
Mongoid.raise_not_found_error = (true|false)
|
333
|
+
|
334
|
+
- When set to false, a Mongoid::Errors::DocumentNotFound
|
335
|
+
will NOT get thrown when performing a Document.find(id)
|
336
|
+
that does not return a document from the database.
|
337
|
+
This defaults to true.
|
338
|
+
|
339
|
+
- Mongoid::Document.collection_name macro added. You can
|
340
|
+
now set the name of the database collection to persist to.
|
341
|
+
|
342
|
+
- Mongoid::Criteria#select becomes Mongoid::Criteria#only
|
data/README.rdoc
CHANGED
@@ -8,13 +8,20 @@ Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby.
|
|
8
8
|
|
9
9
|
* {Mongoid on Pivotal Tracker}[http://www.pivotaltracker.com/projects/27482]
|
10
10
|
* {Mongoid Google Group}[http://groups.google.com/group/mongoid]
|
11
|
-
* {Mongoid on CI Joe}[http://
|
11
|
+
* {Mongoid on CI Joe}[http://mongoid.org:4444/]
|
12
12
|
* {Mongoid Website and Documentation}[http://mongoid.org]
|
13
13
|
|
14
14
|
== Compatibility
|
15
15
|
|
16
16
|
Mongoid is developed against Ruby 1.8.6, 1.8.7, 1.9.1, 1.9.2
|
17
17
|
|
18
|
+
Note API changes will be frequent until 1.0, releases will be
|
19
|
+
frequent, and backwards compatibility will not be supported. Do not
|
20
|
+
expect the gem to be of full production quality until that
|
21
|
+
point. However, once 1.0 is released I will be providing backwards
|
22
|
+
compatibility through each minor version upgrade, as well as detailed
|
23
|
+
release notes and documentation with each release.
|
24
|
+
|
18
25
|
= Documentation
|
19
26
|
|
20
27
|
Please see the new Mongoid website for up-to-date documentation:
|
data/Rakefile
CHANGED
@@ -14,9 +14,8 @@ begin
|
|
14
14
|
|
15
15
|
gem.add_dependency("activemodel", ">= 3.0.pre")
|
16
16
|
gem.add_dependency("will_paginate", ">= 3.0.pre")
|
17
|
-
gem.add_dependency("mongo", ">= 0.
|
18
|
-
|
19
|
-
gem.add_development_dependency("rspec", ">= 1.3.0")
|
17
|
+
gem.add_dependency("mongo", ">= 0.18.2")
|
18
|
+
gem.add_development_dependency("rspec", ">= 1.2.9")
|
20
19
|
gem.add_development_dependency("mocha", ">= 0.9.8")
|
21
20
|
end
|
22
21
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0.
|
1
|
+
2.0.0.pre
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
3
|
module Associations #:nodoc:
|
4
|
-
class
|
4
|
+
class BelongsTo #:nodoc:
|
5
5
|
include Proxy
|
6
6
|
|
7
7
|
# Creates the new association by setting the internal
|
@@ -43,16 +43,16 @@ module Mongoid #:nodoc:
|
|
43
43
|
|
44
44
|
# Returns the macro used to create the association.
|
45
45
|
def macro
|
46
|
-
:
|
46
|
+
:belongs_to
|
47
47
|
end
|
48
48
|
|
49
49
|
# Perform an update of the relationship of the parent and child. This
|
50
50
|
# is initialized by setting a parent object as the association on the
|
51
|
-
# +Document+. Will properly set
|
51
|
+
# +Document+. Will properly set a has_one or a has_many.
|
52
52
|
#
|
53
53
|
# Returns:
|
54
54
|
#
|
55
|
-
# A new +
|
55
|
+
# A new +BelongsTo+ association proxy.
|
56
56
|
def update(target, child, options)
|
57
57
|
child.parentize(target, options.inverse_of)
|
58
58
|
child.notify
|
@@ -41,16 +41,19 @@ module Mongoid #:nodoc:
|
|
41
41
|
#
|
42
42
|
# Options:
|
43
43
|
#
|
44
|
-
#
|
45
|
-
#
|
44
|
+
# related: The related object
|
45
|
+
# parent: The parent +Document+ to update.
|
46
46
|
# options: The association +Options+
|
47
47
|
#
|
48
48
|
# Example:
|
49
49
|
#
|
50
|
-
# <tt>BelongsToRelated.update(
|
51
|
-
def update(target,
|
52
|
-
|
53
|
-
|
50
|
+
# <tt>BelongsToRelated.update(game, person, options)</tt>
|
51
|
+
def update(target, parent, options)
|
52
|
+
if target
|
53
|
+
parent.send("#{options.foreign_key}=", target.id)
|
54
|
+
return instantiate(parent, options, target)
|
55
|
+
end
|
56
|
+
target
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
3
|
module Associations #:nodoc:
|
4
|
-
class
|
4
|
+
class HasMany
|
5
5
|
include Proxy
|
6
6
|
|
7
7
|
attr_accessor :association_name, :klass
|
8
8
|
|
9
9
|
# Appends the object to the +Array+, setting its parent in
|
10
10
|
# the process.
|
11
|
-
def <<(*
|
12
|
-
|
13
|
-
|
14
|
-
@target <<
|
15
|
-
|
11
|
+
def <<(*objects)
|
12
|
+
objects.flatten.each do |object|
|
13
|
+
object.parentize(@parent, @association_name)
|
14
|
+
@target << object
|
15
|
+
object.notify
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -22,8 +22,9 @@ module Mongoid #:nodoc:
|
|
22
22
|
# Clears the association, and notifies the parents of the removal.
|
23
23
|
def clear
|
24
24
|
unless @target.empty?
|
25
|
-
|
26
|
-
|
25
|
+
object = @target.first
|
26
|
+
object.changed(true)
|
27
|
+
object.notify_observers(object, true)
|
27
28
|
@target.clear
|
28
29
|
end
|
29
30
|
end
|
@@ -36,11 +37,11 @@ module Mongoid #:nodoc:
|
|
36
37
|
#
|
37
38
|
# The newly created Document.
|
38
39
|
def build(attrs = {}, type = nil)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@target <<
|
43
|
-
|
40
|
+
object = type ? type.instantiate : @klass.instantiate
|
41
|
+
object.parentize(@parent, @association_name)
|
42
|
+
object.write_attributes(attrs)
|
43
|
+
@target << object
|
44
|
+
object
|
44
45
|
end
|
45
46
|
|
46
47
|
# Creates a new Document and adds it to the association collection. The
|
@@ -50,26 +51,11 @@ module Mongoid #:nodoc:
|
|
50
51
|
#
|
51
52
|
# Returns:
|
52
53
|
#
|
53
|
-
#
|
54
|
+
# Rhe newly created Document.
|
54
55
|
def create(attrs = {}, type = nil)
|
55
56
|
object = build(attrs, type)
|
56
|
-
object.
|
57
|
-
|
58
|
-
|
59
|
-
# Creates a new Document and adds it to the association collection. The
|
60
|
-
# document created will be of the same class as the others in the
|
61
|
-
# association, and the attributes will be passed into the constructor and
|
62
|
-
# the new object will then be saved. If validation fails an error will
|
63
|
-
# get raised.
|
64
|
-
#
|
65
|
-
# Returns:
|
66
|
-
#
|
67
|
-
# The newly created Document.
|
68
|
-
def create!(attrs = {}, type = nil)
|
69
|
-
document = create(attrs, type)
|
70
|
-
errors = document.errors
|
71
|
-
raise Errors::Validations.new(errors) unless errors.empty?
|
72
|
-
document
|
57
|
+
object.save
|
58
|
+
object
|
73
59
|
end
|
74
60
|
|
75
61
|
# Finds a document in this association.
|
@@ -163,7 +149,7 @@ module Mongoid #:nodoc:
|
|
163
149
|
|
164
150
|
class << self
|
165
151
|
|
166
|
-
# Preferred method of creating a new +
|
152
|
+
# Preferred method of creating a new +HasMany+ association. It will
|
167
153
|
# delegate to new.
|
168
154
|
#
|
169
155
|
# Options:
|
@@ -176,7 +162,7 @@ module Mongoid #:nodoc:
|
|
176
162
|
|
177
163
|
# Returns the macro used to create the association.
|
178
164
|
def macro
|
179
|
-
:
|
165
|
+
:has_many
|
180
166
|
end
|
181
167
|
|
182
168
|
# Perform an update of the relationship of the parent and child. This
|
@@ -188,6 +174,7 @@ module Mongoid #:nodoc:
|
|
188
174
|
instantiate(parent, options)
|
189
175
|
end
|
190
176
|
end
|
177
|
+
|
191
178
|
end
|
192
179
|
end
|
193
180
|
end
|
@@ -7,7 +7,6 @@ module Mongoid #:nodoc:
|
|
7
7
|
# Appends the object to the +Array+, setting its parent in
|
8
8
|
# the process.
|
9
9
|
def <<(*objects)
|
10
|
-
load_target
|
11
10
|
objects.flatten.each do |object|
|
12
11
|
object.send("#{@foreign_key}=", @parent.id)
|
13
12
|
@target << object
|
@@ -21,7 +20,6 @@ module Mongoid #:nodoc:
|
|
21
20
|
#
|
22
21
|
# Returns the newly created object.
|
23
22
|
def build(attributes = {})
|
24
|
-
load_target
|
25
23
|
name = @parent.class.to_s.underscore
|
26
24
|
object = @klass.instantiate(attributes.merge(name => @parent))
|
27
25
|
@target << object
|
@@ -41,7 +39,8 @@ module Mongoid #:nodoc:
|
|
41
39
|
# Returns the newly created object.
|
42
40
|
def create(attributes)
|
43
41
|
object = build(attributes)
|
44
|
-
object.
|
42
|
+
object.save
|
43
|
+
object
|
45
44
|
end
|
46
45
|
|
47
46
|
# Finds a document in this association.
|
@@ -60,39 +59,16 @@ module Mongoid #:nodoc:
|
|
60
59
|
# options: The association +Options+.
|
61
60
|
def initialize(document, options, target = nil)
|
62
61
|
@parent, @klass = document, options.klass
|
63
|
-
@foreign_key =
|
64
|
-
@
|
65
|
-
@target = target || @base.call
|
62
|
+
@foreign_key = document.class.to_s.foreign_key
|
63
|
+
@target = target || @klass.all(:conditions => { @foreign_key => document.id })
|
66
64
|
extends(options)
|
67
65
|
end
|
68
66
|
|
69
|
-
# Override the default behavior to allow the criteria to get reset on
|
70
|
-
# each call into the association.
|
71
|
-
#
|
72
|
-
# Example:
|
73
|
-
#
|
74
|
-
# person.posts.where(:title => "New")
|
75
|
-
# person.posts # resets the criteria
|
76
|
-
#
|
77
|
-
# Returns:
|
78
|
-
#
|
79
|
-
# A Criteria object or Array.
|
80
|
-
def method_missing(name, *args, &block)
|
81
|
-
@target = @base.call unless @target.is_a?(Array)
|
82
|
-
@target.send(name, *args, &block)
|
83
|
-
end
|
84
|
-
|
85
67
|
# Delegates to <<
|
86
68
|
def push(*objects)
|
87
69
|
self << objects
|
88
70
|
end
|
89
71
|
|
90
|
-
protected
|
91
|
-
# Load the target entries if the document is new.
|
92
|
-
def load_target
|
93
|
-
@target = @target.entries if @parent.new_record?
|
94
|
-
end
|
95
|
-
|
96
72
|
class << self
|
97
73
|
# Preferred method for creating the new +HasManyRelated+ association.
|
98
74
|
#
|