activerecord-precounter 0.3.2 → 0.3.3
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/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/lib/active_record/precounter.rb +12 -5
- data/lib/active_record/precounter/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09078896e68490e75c8beb5645afcd62ad0d5ea91c00e4bce6caf56c78fef5a8'
|
4
|
+
data.tar.gz: 584556fa31db7232716409333ddc670679846fab59660a66c20432eef6eb95b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 978b940f2cc5adf4206bb399fbdb0e35f745336095df5a411d9d7fc98e9c3f43b3e0974c905d23b3d96811c9a55cc75d1da1aa3c1f3317b3c33cc20412224d6d
|
7
|
+
data.tar.gz: 194cd5631328971a328c71ecf853cf80f10f309dff0cf3ff23a9b57275d3bd78b00cfd43ff8e070f6c023d0b5a4183b92fd03e9f2e2edc08e0f18257af38234f
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## v0.3.3
|
2
|
+
|
3
|
+
* Support passing a single record to `ActiveRecord::Precounter.new` [#8](https://github.com/k0kubun/activerecord-precounter/pull/8)
|
4
|
+
|
1
5
|
## v0.3.2
|
2
6
|
|
3
7
|
* Support primary\_key option of belongs\_to association [#7](https://github.com/k0kubun/activerecord-precounter/pull/7)
|
@@ -12,17 +12,24 @@ module ActiveRecord
|
|
12
12
|
# @param [Array<String,Symbol>] association_names - Eager loaded association names. e.g. `[:users, :likes]`
|
13
13
|
# @return [Array<ActiveRecord::Base>]
|
14
14
|
def precount(*association_names)
|
15
|
-
|
16
|
-
return
|
15
|
+
# Allow single record instances as well as relations to be passed.
|
16
|
+
# The splat here will return an array of the single record if it's
|
17
|
+
# not a relation or otherwise return the records themselves via #to_a.
|
18
|
+
records = *@relation
|
19
|
+
return records if records.empty?
|
20
|
+
|
21
|
+
# We need to get the relation's active class, which is the class itself
|
22
|
+
# in the case of a single record.
|
23
|
+
klass = @relation.respond_to?(:klass) ? @relation.klass : @relation.class
|
17
24
|
|
18
25
|
association_names.each do |association_name|
|
19
26
|
association_name = association_name.to_s
|
20
|
-
reflection =
|
27
|
+
reflection = klass.reflections.fetch(association_name)
|
21
28
|
|
22
29
|
if reflection.inverse_of.nil?
|
23
30
|
raise MissingInverseOf.new(
|
24
|
-
"`#{reflection.klass}` does not have inverse of `#{
|
25
|
-
"Probably missing to call `#{reflection.klass}.belongs_to #{
|
31
|
+
"`#{reflection.klass}` does not have inverse of `#{klass}##{reflection.name}`. "\
|
32
|
+
"Probably missing to call `#{reflection.klass}.belongs_to #{klass.name.underscore.to_sym.inspect}`?"
|
26
33
|
)
|
27
34
|
end
|
28
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-precounter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -153,8 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
|
-
|
157
|
-
rubygems_version: 2.7.6
|
156
|
+
rubygems_version: 3.0.3
|
158
157
|
signing_key:
|
159
158
|
specification_version: 4
|
160
159
|
summary: Yet Another N+1 COUNT Query Killer for ActiveRecord
|