mongoid_includes 2.1.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/lib/mongoid/includes/{relations → association}/eager.rb +2 -2
- data/lib/mongoid/includes/criteria.rb +1 -1
- data/lib/mongoid/includes/inclusion.rb +9 -15
- data/lib/mongoid/includes/inclusions.rb +8 -3
- data/lib/mongoid/includes/version.rb +1 -1
- data/lib/mongoid/includes.rb +1 -1
- data/lib/mongoid_includes.rb +1 -1
- data/spec/mongo.log +3347 -6656
- data/spec/mongoid/includes/inclusions_spec.rb +3 -5
- data/spec/mongoid/includes/polymorphic_includes_spec.rb +9 -3
- data/spec/mongoid/includes/simple_inclusions_spec.rb +1 -13
- data/spec/spec_helper.rb +7 -11
- data/spec/support/helpers.rb +13 -36
- data/spec/support/models/address.rb +1 -37
- data/spec/support/models/game.rb +1 -5
- data/spec/support/models/musician.rb +0 -4
- data/spec/support/models/person.rb +3 -18
- data/spec/support/models/post.rb +2 -0
- data/spec/support/models/record.rb +0 -43
- metadata +11 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1fe48fd0ac7d46fb5fe158bac336bfff3a8dde974f10629e3f632fcb3e475e18
|
4
|
+
data.tar.gz: db7fb5e32b06be95c8e133d48e8882249d623528a4bba05220f762b9a436adc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b2e350afb5abc0488ce860052522147cf97f15bd2bbbbda207094e00b2ec0807f281bd44af5f4991eca80139d7d23946a749bf40b3ded0e6ce5d40e870e8243
|
7
|
+
data.tar.gz: e8bd1062e78e5ed04c1a3c9d1377c218f40c06c4d7f85a917c5df90a588516168ac670c01b8f8f86fc8c7addc89bf84c4443248a3f0c3ba0af719a799ed64936
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## Mongoid::Includes 3.0.0 (2020-10-29) ##
|
2
|
+
|
3
|
+
* Add support for Mongoid `7.1`.
|
4
|
+
* Avoid making a query when the foreign keys are empty.
|
5
|
+
|
1
6
|
## Mongoid::Includes 2.1.0 (2017-07-03) ##
|
2
7
|
|
3
8
|
* Fix bug where `includes` ignores the `:with` option if the association is polymorphic. Thanks @nickcherry for the bug report!
|
data/README.md
CHANGED
@@ -3,9 +3,9 @@ Mongoid::Includes
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/mongoid_includes.svg)](http://badge.fury.io/rb/mongoid_includes)
|
4
4
|
[![Build Status](https://travis-ci.org/ElMassimo/mongoid_includes.svg)](https://travis-ci.org/ElMassimo/mongoid_includes)
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/ElMassimo/mongoid_includes/badges/coverage.svg)](https://codeclimate.com/github/ElMassimo/mongoid_includes)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/ElMassimo/mongoid_includes.
|
6
|
+
[![Code Climate](https://codeclimate.com/github/ElMassimo/mongoid_includes.svg)](https://codeclimate.com/github/ElMassimo/mongoid_includes)
|
7
7
|
[![Inline docs](http://inch-ci.org/github/ElMassimo/mongoid_includes.svg)](http://inch-ci.org/github/ElMassimo/mongoid_includes)
|
8
|
-
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/mongoid_includes/blob/
|
8
|
+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/mongoid_includes/blob/main/LICENSE.txt)
|
9
9
|
|
10
10
|
`Mongoid::Includes` improves eager loading in Mongoid, supporting polymorphic associations, and nested eager loading.
|
11
11
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module Includes
|
3
|
-
module
|
3
|
+
module Association
|
4
4
|
|
5
5
|
# Internal: Patch to the base class for eager load preload functions,
|
6
6
|
# that interacts with the Mongoid::Includes::Inclusion as @medatada.
|
@@ -9,7 +9,7 @@ module Mongoid
|
|
9
9
|
# Internal: Performs eager load and iterates over the preloaded documents
|
10
10
|
# for the current relation.
|
11
11
|
def each_loaded_document
|
12
|
-
@
|
12
|
+
@association.load_documents_for(key, keys_from_docs).each do |doc|
|
13
13
|
yield doc
|
14
14
|
end
|
15
15
|
end
|
@@ -19,7 +19,7 @@ module Mongoid
|
|
19
19
|
# loaded from.
|
20
20
|
# from_class: - Necessary to solve ambiguity when doing two-level eager
|
21
21
|
# load through a polymorphic relation.
|
22
|
-
#
|
22
|
+
# with: - An optional block that specifies how to load all the
|
23
23
|
# related documents.
|
24
24
|
#
|
25
25
|
# Notes:
|
@@ -25,7 +25,7 @@ module Mongoid
|
|
25
25
|
|
26
26
|
# Public: Returns true if the relation is a polymorphic belongs_to.
|
27
27
|
def polymorphic_belongs_to?
|
28
|
-
metadata.polymorphic? && metadata.relation == Mongoid::
|
28
|
+
metadata.polymorphic? && metadata.relation == Mongoid::Association::Referenced::BelongsTo::Proxy
|
29
29
|
end
|
30
30
|
|
31
31
|
# Public: Name of the relation from which a nested inclusion is performed.
|
@@ -33,11 +33,6 @@ module Mongoid
|
|
33
33
|
@from ||= @options[:from]
|
34
34
|
end
|
35
35
|
|
36
|
-
# Internal: Proc that will return the included documents from a set of foreign keys.
|
37
|
-
def loader
|
38
|
-
@loader ||= @options[:loader]
|
39
|
-
end
|
40
|
-
|
41
36
|
# Internal: Proc that will modify the documents to include in the relation.
|
42
37
|
def modifier
|
43
38
|
@modifier ||= @options[:with]
|
@@ -46,12 +41,11 @@ module Mongoid
|
|
46
41
|
# Public: Preloads the documents for the relation. Uses a custom block
|
47
42
|
# if one was provided, or fetches them using the class and the foreign key.
|
48
43
|
def load_documents_for(foreign_key, foreign_key_values)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
44
|
+
# NOTE: We assume the upstream code in Mongoid is removing nil keys.
|
45
|
+
return klass.none if foreign_key_values.empty?
|
46
|
+
|
47
|
+
docs = klass.any_in(foreign_key => foreign_key_values)
|
48
|
+
modifier ? modifier.call(docs) : docs
|
55
49
|
end
|
56
50
|
|
57
51
|
# Public: Clones the inclusion and changes the Mongoid::Metadata::Relation
|
@@ -60,10 +54,10 @@ module Mongoid
|
|
60
54
|
# Returns an Inclusion that can be eager loaded as usual.
|
61
55
|
def for_class_name(class_name)
|
62
56
|
Inclusion.new metadata.clone.instance_eval { |relation_metadata|
|
63
|
-
|
64
|
-
|
57
|
+
@options[:class_name] = @class_name = class_name
|
58
|
+
@options[:polymorphic], @options[:as], @polymorphic, @klass = nil
|
65
59
|
self
|
66
|
-
}, with: @modifier
|
60
|
+
}, with: @modifier
|
67
61
|
end
|
68
62
|
end
|
69
63
|
end
|
@@ -11,15 +11,20 @@ module Mongoid
|
|
11
11
|
super Set.new(object)
|
12
12
|
end
|
13
13
|
|
14
|
+
# Override: Avoid replacing existing inclusions.
|
15
|
+
def add(metadata)
|
16
|
+
include?(metadata) ? metadata : super
|
17
|
+
end
|
18
|
+
|
14
19
|
# Public: Adds a new relation as an inclusion.
|
15
20
|
#
|
16
21
|
# Returns the added inclusion.
|
17
22
|
def push(metadata, options = {})
|
18
23
|
metadata = Inclusion.new(metadata, options) unless metadata.is_a?(Inclusion)
|
19
24
|
|
20
|
-
# Ensure that an inclusion with a specified
|
21
|
-
#
|
22
|
-
delete(metadata) if metadata.
|
25
|
+
# Ensure that an inclusion with a specified modifier replaces a
|
26
|
+
# previously specified one.
|
27
|
+
delete(metadata) if metadata.modifier
|
23
28
|
|
24
29
|
# Internally it's a set so it won't add it twice.
|
25
30
|
add(metadata)
|
data/lib/mongoid/includes.rb
CHANGED
data/lib/mongoid_includes.rb
CHANGED
@@ -9,4 +9,4 @@ Mongoid::Contextual::Mongo.send :prepend, Mongoid::Includes::EagerLoad
|
|
9
9
|
Mongoid::Contextual::Memory.send :prepend, Mongoid::Includes::EagerLoad
|
10
10
|
|
11
11
|
Mongoid::Criteria.send :prepend, Mongoid::Includes::Criteria
|
12
|
-
Mongoid::
|
12
|
+
Mongoid::Association::Referenced::Eager::Base.send :prepend, Mongoid::Includes::Association::Eager
|