mongoid 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,6 +56,18 @@ module Mongoid #:nodoc:
56
56
  return false unless other.is_a?(self.class)
57
57
  self.key == other.key && self.operator == other.operator
58
58
  end
59
+
60
+ # Returns the name of the key as a string.
61
+ #
62
+ # @example Get the name of the key.
63
+ # criterion.to_s
64
+ #
65
+ # @return [ String ] The field name.
66
+ #
67
+ # @since 2.1.0
68
+ def to_s
69
+ key.to_s
70
+ end
59
71
  end
60
72
  end
61
73
  end
@@ -46,7 +46,7 @@ module Mongoid #:nodoc:
46
46
  #
47
47
  # @return [ true, false ] True if the classes are equal, false if not.
48
48
  def ===(other)
49
- self.class == other.class
49
+ other.is_a?(self.class)
50
50
  end
51
51
 
52
52
  # Delegates to ==. Used when needing checks in hashes.
@@ -159,6 +159,7 @@ module Mongoid #:nodoc:
159
159
  remove_instance_variable("@#{name}")
160
160
  end
161
161
  end
162
+ run_callbacks(:initialize)
162
163
  end
163
164
  end
164
165
 
@@ -80,7 +80,7 @@ module Mongoid # :nodoc:
80
80
  #
81
81
  # @since 2.0.0.rc.1
82
82
  def cyclic_parent_name
83
- ("parent_" << self.name.underscore.singularize).to_sym
83
+ ("parent_" << self.name.demodulize.underscore.singularize).to_sym
84
84
  end
85
85
 
86
86
  # Determines the child name given the class.
@@ -95,7 +95,7 @@ module Mongoid # :nodoc:
95
95
  #
96
96
  # @since 2.0.0.rc.1
97
97
  def cyclic_child_name(many = true)
98
- ("child_" << self.name.underscore.send(many ? :pluralize : :singularize)).to_sym
98
+ ("child_" << self.name.demodulize.underscore.send(many ? :pluralize : :singularize)).to_sym
99
99
  end
100
100
  end
101
101
  end
@@ -123,7 +123,10 @@ module Mongoid # :nodoc:
123
123
  # @since 2.0.0.rc.1
124
124
  def delete(document)
125
125
  target.delete_one(document).tap do |doc|
126
- unbind_one(doc) if doc && !binding?
126
+ if doc && !binding?
127
+ unbind_one(doc)
128
+ doc.delete(:suppress => true)
129
+ end
127
130
  reindex
128
131
  end
129
132
  end
@@ -83,6 +83,18 @@ module Mongoid #:nodoc:
83
83
  [].respond_to?(name, include_private) || super
84
84
  end
85
85
 
86
+ # This is public access to the relation's criteria.
87
+ #
88
+ # @example Get the scoped relation.
89
+ # relation.scoped
90
+ #
91
+ # @return [ Criteria ] The scoped criteria.
92
+ #
93
+ # @since 2.1.0
94
+ def scoped
95
+ criteria
96
+ end
97
+
86
98
  # Gets the document as a serializable hash, used by ActiveModel's JSON and
87
99
  # XML serializers. This override is just to be able to pass the :include
88
100
  # and :except options to get associations in the hash.
@@ -60,23 +60,6 @@ module Mongoid #:nodoc:
60
60
  end
61
61
  alias :new :build
62
62
 
63
- # Clear the relation. Will delete the documents from the db if they are
64
- # already persisted.
65
- #
66
- # @example Clear the relation.
67
- # person.posts.clear
68
- #
69
- # @return [ Many ] The relation emptied.
70
- #
71
- # @since 2.0.0.beta.1
72
- def clear
73
- criteria.delete_all
74
- target.clear do |doc|
75
- unbind_one(doc)
76
- doc.destroyed = true
77
- end
78
- end
79
-
80
63
  # Creates a new document on the references many relation. This will
81
64
  # save the document if the parent has been persisted.
82
65
  #
@@ -259,6 +242,24 @@ module Mongoid #:nodoc:
259
242
  end
260
243
  alias :nullify_all :nullify
261
244
 
245
+ # Clear the relation. Will delete the documents from the db if they are
246
+ # already persisted.
247
+ #
248
+ # @example Clear the relation.
249
+ # person.posts.clear
250
+ #
251
+ # @return [ Many ] The relation emptied.
252
+ #
253
+ # @since 2.0.0.beta.1
254
+ def purge
255
+ criteria.delete_all
256
+ target.clear do |doc|
257
+ unbind_one(doc)
258
+ doc.destroyed = true
259
+ end
260
+ end
261
+ alias :clear :purge
262
+
262
263
  # Substitutes the supplied target documents for the existing documents
263
264
  # in the relation. If the new target is nil, perform the necessary
264
265
  # deletion.
@@ -273,7 +274,7 @@ module Mongoid #:nodoc:
273
274
  # @since 2.0.0.rc.1
274
275
  def substitute(replacement)
275
276
  tap do |proxy|
276
- proxy.clear
277
+ proxy.purge
277
278
  proxy.push(replacement) if replacement
278
279
  end
279
280
  end
@@ -171,14 +171,19 @@ module Mongoid # :nodoc:
171
171
  #
172
172
  # @since 2.0.0.rc.1
173
173
  def nullify
174
- # @todo: Durran: This is wrong.
175
- criteria.update(metadata.inverse_foreign_key => [])
176
- # We need to update the inverse as well.
174
+ criteria.pull(metadata.inverse_foreign_key, base.id)
175
+ unless base.destroyed?
176
+ base.set(
177
+ metadata.foreign_key,
178
+ base.send(metadata.foreign_key).clear
179
+ )
180
+ end
177
181
  target.clear do |doc|
178
182
  unbind_one(doc)
179
183
  end
180
184
  end
181
185
  alias :nullify_all :nullify
186
+ alias :clear :nullify
182
187
 
183
188
  private
184
189
 
@@ -26,7 +26,7 @@ module Mongoid #:nodoc:
26
26
  # @since 2.0.0.rc.1
27
27
  def read_attribute_for_validation(attr)
28
28
  if relations[attr.to_s]
29
- relation = ivar(attr)
29
+ relation = send(attr)
30
30
  relation ? relation.in_memory : nil
31
31
  else
32
32
  send(attr)
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.1.2"
3
+ VERSION = "2.1.3"
4
+ VERSION_DATE = "2011-08-03"
4
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-31 00:00:00.000000000 %:z
12
+ date: 2011-08-03 00:00:00.000000000 %:z
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &2151774380 !ruby/object:Gem::Requirement
17
+ requirement: &2151762700 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2151774380
25
+ version_requirements: *2151762700
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: tzinfo
28
- requirement: &2151772820 !ruby/object:Gem::Requirement
28
+ requirement: &2151761080 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.3.22
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2151772820
36
+ version_requirements: *2151761080
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: mongo
39
- requirement: &2151770980 !ruby/object:Gem::Requirement
39
+ requirement: &2151759440 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '1.3'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2151770980
47
+ version_requirements: *2151759440
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rdoc
50
- requirement: &2151758560 !ruby/object:Gem::Requirement
50
+ requirement: &2151746880 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 3.5.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2151758560
58
+ version_requirements: *2151746880
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: bson_ext
61
- requirement: &2151755800 !ruby/object:Gem::Requirement
61
+ requirement: &2151744200 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '1.3'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2151755800
69
+ version_requirements: *2151744200
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mocha
72
- requirement: &2151752500 !ruby/object:Gem::Requirement
72
+ requirement: &2151742640 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 0.9.8
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2151752500
80
+ version_requirements: *2151742640
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rspec
83
- requirement: &2151750800 !ruby/object:Gem::Requirement
83
+ requirement: &2151740940 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '2.6'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2151750800
91
+ version_requirements: *2151740940
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: watchr
94
- requirement: &2151748540 !ruby/object:Gem::Requirement
94
+ requirement: &2151738900 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: '0.6'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *2151748540
102
+ version_requirements: *2151738900
103
103
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
104
104
  in Ruby.
105
105
  email:
@@ -380,7 +380,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
380
380
  version: '0'
381
381
  segments:
382
382
  - 0
383
- hash: 1067199592280239396
383
+ hash: -3549058104272802333
384
384
  required_rubygems_version: !ruby/object:Gem::Requirement
385
385
  none: false
386
386
  requirements: