mongoid 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,8 +42,10 @@ module Mongoid #:nodoc:
42
42
  #
43
43
  # @return [ Integer ] The count of documents.
44
44
  def count
45
- @count ||= filter.size
45
+ @count ||= execute.size
46
46
  end
47
+ alias :length :count
48
+ alias :size :count
47
49
 
48
50
  # Delete all the documents in the database matching the selector.
49
51
  #
@@ -88,6 +88,8 @@ module Mongoid #:nodoc:
88
88
  def count(extras = false)
89
89
  @count ||= klass.collection.find(selector, process_options).count(extras)
90
90
  end
91
+ alias :size :count
92
+ alias :length :count
91
93
 
92
94
  # Delete all the documents in the database matching the selector.
93
95
  #
@@ -47,6 +47,8 @@ module Mongoid #:nodoc:
47
47
  :avg,
48
48
  :blank?,
49
49
  :count,
50
+ :size,
51
+ :length,
50
52
  :delete,
51
53
  :delete_all,
52
54
  :destroy,
@@ -111,6 +111,11 @@ module Rails #:nodoc:
111
111
  end
112
112
  end
113
113
 
114
+ # Need to include the Mongoid identity map middleware.
115
+ initializer "include the identity map" do |app|
116
+ app.config.middleware.use "Rack::Mongoid::Middleware::IdentityMap"
117
+ end
118
+
114
119
  # Instantitate any registered observers after Rails initialization and
115
120
  # instantiate them after being reloaded in the development environment
116
121
  initializer "instantiate observers" do
@@ -112,7 +112,7 @@ module Mongoid # :nodoc:
112
112
  # attrs: The single document attributes to process.
113
113
  def process(attrs)
114
114
  return if reject?(attrs)
115
- if id = attrs[:id] || attrs["id"] || attrs["_id"]
115
+ if id = attrs["id"] || attrs["_id"]
116
116
  document = existing.find(convert_id(id))
117
117
  destroyable?(attrs) ? existing.delete(document) : document.update_attributes(attrs)
118
118
  else
@@ -228,7 +228,7 @@ module Mongoid # :nodoc:
228
228
  proxy.clear
229
229
  else
230
230
  atomically(:$set) do
231
- proxy.target = replacement
231
+ proxy.target = replacement.compact
232
232
  proxy.target.each_with_index do |doc, index|
233
233
  integrate(doc)
234
234
  doc._index = index
@@ -391,6 +391,16 @@ module Mongoid # :nodoc:
391
391
  @inverse_klass ||= inverse_class_name.constantize
392
392
  end
393
393
 
394
+ # Get the metadata for the inverse relation.
395
+ #
396
+ # @example Get the inverse metadata.
397
+ # metadata.inverse_metadata(doc)
398
+ #
399
+ # @param [ Document ] document The document to check.
400
+ #
401
+ # @return [ Metadata ] The inverse metadata.
402
+ #
403
+ # @since 2.1.0
394
404
  def inverse_metadata(document)
395
405
  document.reflect_on_association(inverse(document))
396
406
  end
@@ -767,9 +777,10 @@ module Mongoid # :nodoc:
767
777
  #
768
778
  # @since 2.0.0.rc.1
769
779
  def determine_inverse_relation
780
+ default = klass.relations[inverse_klass.name.underscore]
781
+ return default.name if default
770
782
  klass.relations.each_pair do |key, meta|
771
- if key == inverse_klass.name.underscore ||
772
- meta.class_name == inverse_class_name
783
+ if meta.class_name == inverse_class_name
773
784
  return key.to_sym
774
785
  end
775
786
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.1.1"
3
+ VERSION = "2.1.2"
4
4
  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.1
4
+ version: 2.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &2151817520 !ruby/object:Gem::Requirement
17
+ requirement: &2151774380 !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: *2151817520
25
+ version_requirements: *2151774380
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: tzinfo
28
- requirement: &2151806700 !ruby/object:Gem::Requirement
28
+ requirement: &2151772820 !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: *2151806700
36
+ version_requirements: *2151772820
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: mongo
39
- requirement: &2151801860 !ruby/object:Gem::Requirement
39
+ requirement: &2151770980 !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: *2151801860
47
+ version_requirements: *2151770980
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rdoc
50
- requirement: &2151792280 !ruby/object:Gem::Requirement
50
+ requirement: &2151758560 !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: *2151792280
58
+ version_requirements: *2151758560
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: bson_ext
61
- requirement: &2151790140 !ruby/object:Gem::Requirement
61
+ requirement: &2151755800 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,21 +66,21 @@ dependencies:
66
66
  version: '1.3'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2151790140
69
+ version_requirements: *2151755800
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mocha
72
- requirement: &2151788460 !ruby/object:Gem::Requirement
72
+ requirement: &2151752500 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - =
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 0.9.8
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2151788460
80
+ version_requirements: *2151752500
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rspec
83
- requirement: &2151786380 !ruby/object:Gem::Requirement
83
+ requirement: &2151750800 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,18 +88,18 @@ dependencies:
88
88
  version: '2.6'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2151786380
91
+ version_requirements: *2151750800
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: watchr
94
- requirement: &2151784760 !ruby/object:Gem::Requirement
94
+ requirement: &2151748540 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
- - - =
97
+ - - ~>
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0.6'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *2151784760
102
+ version_requirements: *2151748540
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: -4071051164423379877
383
+ hash: 1067199592280239396
384
384
  required_rubygems_version: !ruby/object:Gem::Requirement
385
385
  none: false
386
386
  requirements: