mongoid_includes 3.0.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +66 -7
- data/lib/mongoid/includes/inclusion.rb +1 -0
- data/lib/mongoid/includes/version.rb +1 -6
- data/spec/mongo.log +41651 -0
- data/spec/mongoid/includes/polymorphic_includes_spec.rb +112 -0
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83db65c1adea9fd5ce752f9867989788d8859ffd1e1b1a9fe859ebe83fcd4846
|
4
|
+
data.tar.gz: 4d8cc4f621f9f8f44bf76f33fcdb8d69be082e971d1cc961a8e430af526d4359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbb0d5ffb72235011a22273a55acf1bbd127ac94fedb985336eecad14caf9e0b75d850e9f1e086160bac8270b1a6332cb3c4e10afa8d521766213d3171c42d83
|
7
|
+
data.tar.gz: cbd607eb7b26276e115880af07fc1b179401ed1d334a4ccb76322ebc28452ab1b2e5c983392c90eb4d2e501ac342dfc7617dd63ec709393aa62cbdf93405d481
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
Mongoid::Includes
|
2
|
-
=====================
|
1
|
+
# Mongoid::Includes
|
3
2
|
|
4
3
|
[](https://rubygems.org/gems/mongoid_includes)
|
5
|
-
[](https://github.com/cacheventures/mongoid_includes/actions)
|
6
5
|
|
7
6
|
`Mongoid::Includes` improves eager loading in Mongoid, supporting polymorphic associations, and nested eager loading.
|
8
7
|
|
9
|
-
|
8
|
+
## Usage
|
10
9
|
|
11
10
|
```ruby
|
12
11
|
Album.includes(:songs).includes(:musicians, from: :band)
|
@@ -19,8 +18,10 @@ released_only = ->(albums) { albums.where(released: true) }
|
|
19
18
|
Musician.includes(:band, with: ->(bands) { bands.limit(2).includes(:albums, with: released_only) })
|
20
19
|
```
|
21
20
|
|
22
|
-
|
21
|
+
## Pro Tip
|
22
|
+
|
23
23
|
Since you can modify the queries for the associations, you can use `only` and make your queries even faster:
|
24
|
+
|
24
25
|
```ruby
|
25
26
|
Band.includes :musicians, with: ->(musicians) { musicians.only(:id, :name) }
|
26
27
|
```
|
@@ -36,10 +37,10 @@ Band.includes :musicians, with: ->(musicians) { musicians.only(:id, :name) }
|
|
36
37
|
Add this line to your application's Gemfile and run `bundle install`:
|
37
38
|
|
38
39
|
```ruby
|
39
|
-
|
40
|
+
gem 'mongoid_includes'
|
40
41
|
```
|
41
42
|
|
42
|
-
Or install it yourself running:
|
43
|
+
Or install it yourself by running:
|
43
44
|
|
44
45
|
```sh
|
45
46
|
gem install mongoid_includes
|
@@ -48,3 +49,61 @@ gem install mongoid_includes
|
|
48
49
|
## License
|
49
50
|
|
50
51
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
52
|
+
|
53
|
+
## Running tests
|
54
|
+
|
55
|
+
To run the full test suite locally:
|
56
|
+
|
57
|
+
```sh
|
58
|
+
bundle install
|
59
|
+
bundle exec rspec
|
60
|
+
# or use the bundled binary
|
61
|
+
bin/rspec
|
62
|
+
```
|
63
|
+
|
64
|
+
To run the tests against the Mongoid 8 matrix (this project provides a separate Gemfile at `gemfiles/mongoid8.gemfile`), set `BUNDLE_GEMFILE` to that file before installing or running the suite:
|
65
|
+
|
66
|
+
```sh
|
67
|
+
# install gems for the mongoid8 Gemfile
|
68
|
+
BUNDLE_GEMFILE=gemfiles/mongoid8.gemfile bundle install
|
69
|
+
|
70
|
+
# run the specs using that Gemfile
|
71
|
+
BUNDLE_GEMFILE=gemfiles/mongoid8.gemfile bundle exec rspec
|
72
|
+
# or
|
73
|
+
BUNDLE_GEMFILE=gemfiles/mongoid8.gemfile bin/rspec
|
74
|
+
```
|
75
|
+
|
76
|
+
If you only need to run a single spec file while using the alternate Gemfile, pass the path to `rspec` as usual, for example:
|
77
|
+
|
78
|
+
```sh
|
79
|
+
BUNDLE_GEMFILE=gemfiles/mongoid8.gemfile bundle exec rspec spec/mongoid/includes/criteria_spec.rb
|
80
|
+
```
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
Contributions are welcome. If you'd like to report a bug, suggest an improvement, or submit a patch, please follow these steps:
|
85
|
+
|
86
|
+
1. Fork the repository on GitHub.
|
87
|
+
2. Create a feature branch from `master` (or from the branch you're targeting):
|
88
|
+
|
89
|
+
```sh
|
90
|
+
git switch -c my-feature-branch
|
91
|
+
```
|
92
|
+
|
93
|
+
3. Make your changes. Add or update tests when appropriate.
|
94
|
+
4. Run the test suite locally to ensure everything passes:
|
95
|
+
|
96
|
+
```sh
|
97
|
+
bundle install
|
98
|
+
bundle exec rspec
|
99
|
+
```
|
100
|
+
|
101
|
+
5. Commit your changes with a clear message and push your branch to your fork:
|
102
|
+
|
103
|
+
```sh
|
104
|
+
git add -A
|
105
|
+
git commit -m "Short, descriptive message"
|
106
|
+
git push origin my-feature-branch
|
107
|
+
```
|
108
|
+
|
109
|
+
6. Open a Pull Request against the `master` branch of this repository. In your PR description, explain the problem, what you changed, and any notes about compatibility or required steps.
|
@@ -54,6 +54,7 @@ module Mongoid
|
|
54
54
|
# Returns an Inclusion that can be eager loaded as usual.
|
55
55
|
def for_class_name(class_name)
|
56
56
|
Inclusion.new metadata.clone.instance_eval { |relation_metadata|
|
57
|
+
@options = @options.dup
|
57
58
|
@options[:class_name] = @class_name = class_name
|
58
59
|
@options[:polymorphic], @options[:as], @polymorphic, @klass = nil
|
59
60
|
self
|
@@ -1,10 +1,5 @@
|
|
1
|
-
# Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written in Ruby.
|
2
1
|
module Mongoid
|
3
|
-
# Improves eager loading in Mongoid, supporting polymorphic associations,
|
4
|
-
# and up to two-levels of eager loading.
|
5
2
|
module Includes
|
6
|
-
|
7
|
-
# Public: This library will attempt to follow semantic versioning (whatever that's supposed to be).
|
8
|
-
VERSION = '3.0.3'
|
3
|
+
VERSION = '4.0.0'.freeze
|
9
4
|
end
|
10
5
|
end
|