activerecord-precounter 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c85fec9116becd14760b8726df821d422085a4c
4
- data.tar.gz: 5c216798df88c22adfe212b5695e4667600ded38
3
+ metadata.gz: bf992b2001ae6c7bf6ada58116ae081228ab07c6
4
+ data.tar.gz: 0762cdbd9a2ed0924a19cdd9835773250cf5bcba
5
5
  SHA512:
6
- metadata.gz: a472ba502fb21376132e0c8742a50d83c2ac4dc09b39115b592071d26fd2ef5ab20fe94cd2f76db66039e00ebea05504bb36e376d7222e49a1bc335d394cc95f
7
- data.tar.gz: 5c6f1140da169bb55a909fb35b1cee56e5371a772b7c729324c353a992f646bd85730e1c225b3a613701bdd4aa51dc1d0ac1f0a38d7b2bbf52596f7e9bc03495
6
+ metadata.gz: 365ef8fe72218325265a8a3b563c325de40f81d3c65097798a59fdaa4e504cd10bc74d4888480f8202da17d9c3e9ccc4cce03a5ff288e283469cc5e1e9b57846
7
+ data.tar.gz: a56f1bf870d6c334816806bd6712db25f1f6080c5705fbb5104724b8802e192c6580f244436a0ef7012d1a54fdad82b958a21fdc71497a40416c9264dd37a69f
data/.travis.yml CHANGED
@@ -7,27 +7,9 @@ branches:
7
7
  - master
8
8
  matrix:
9
9
  include:
10
- - rvm: 2.1.10
11
- env: TASK=test ARCONN=mysql2
12
- gemfile: ci/Gemfile.activerecord-4.2.x
13
- - rvm: 2.2.7
14
- env: TASK=test ARCONN=mysql2
15
- gemfile: ci/Gemfile.activerecord-5.1.x
16
- - rvm: 2.3.4
17
- env: TASK=test ARCONN=mysql2
18
- gemfile: ci/Gemfile.activerecord-5.1.x
19
- - rvm: 2.4.1
20
- env: TASK=test ARCONN=mysql2
21
- gemfile: ci/Gemfile.activerecord-4.2.x
22
- - rvm: 2.4.1
23
- env: TASK=test ARCONN=mysql2
24
- gemfile: ci/Gemfile.activerecord-5.0.x
25
- - rvm: 2.4.1
26
- env: TASK=test ARCONN=sqlite3
27
- gemfile: ci/Gemfile.activerecord-5.1.x
28
10
  - rvm: 2.4.1
29
- env: TASK=test ARCONN=mysql2
11
+ env: TASK=spec ARCONN=sqlite3
30
12
  gemfile: ci/Gemfile.activerecord-5.1.x
31
13
  - rvm: 2.4.1
32
- env: TASK=test ARCONN=postgresql
14
+ env: TASK=spec ARCONN=postgresql
33
15
  gemfile: ci/Gemfile.activerecord-5.1.x
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  class Precounter
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
@@ -13,7 +13,7 @@ module ActiveRecord
13
13
  # @return [Array<ActiveRecord::Base>]
14
14
  def precount(*association_names)
15
15
  records = @relation.to_a
16
- return if records.empty?
16
+ return [] if records.empty?
17
17
 
18
18
  association_names.each do |association_name|
19
19
  association_name = association_name.to_s
@@ -26,9 +26,15 @@ module ActiveRecord
26
26
  )
27
27
  end
28
28
 
29
- count_by_id = reflection.klass.where(reflection.inverse_of.name => @relation).group(
30
- reflection.inverse_of.foreign_key
31
- ).count
29
+ count_by_id = if reflection.has_scope?
30
+ reflection.scope_for(reflection.klass.where(reflection.inverse_of.name => @relation)).group(
31
+ reflection.inverse_of.foreign_key
32
+ ).count
33
+ else
34
+ reflection.klass.where(reflection.inverse_of.name => @relation).group(
35
+ reflection.inverse_of.foreign_key
36
+ ).count
37
+ end
32
38
 
33
39
  writer = define_count_accessor(records.first, association_name)
34
40
  records.each do |record|
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-12 00:00:00.000000000 Z
11
+ date: 2018-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  requirements: []
154
154
  rubyforge_project:
155
- rubygems_version: 2.5.2
155
+ rubygems_version: 2.6.13
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Yet Another N+1 COUNT Query Killer for ActiveRecord