activerecord-precounter 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa7ed8a641545585e1fcf838262efb66633387a173d65614d9ed7fe4100f2018
4
- data.tar.gz: 2362e9a30228774378634e21f89c26f3cd21dd3051c9e56ba1bc2412e51e06fd
3
+ metadata.gz: a5bf25aa0550622438acc6518baeb060cc7a8b3efb256d398aae6e10575654f8
4
+ data.tar.gz: 51959a62fc7b3bee6bed30512711d7606b0ed3ac756b50fc51ad91ca42ef08ef
5
5
  SHA512:
6
- metadata.gz: 3f7709814cfba9081356cb625c2350ad175384a7d688b439442c565193d315849480ad33b90e04672fa3fa9ebe0ff1a2af194b2c3d5d8853b050096a282cc0d4
7
- data.tar.gz: 21366e80cab47df357670be5febdbbb1bb62bcea232bce497c5295c7adeed52929a59d41ede31d8919b477e2849b073f1a6168a118d18439f3af6d75141bc090
6
+ metadata.gz: 8591c0865cbf9714089fa3ef8230a6cbe09248e49cff8bdbc6dba1dc74c89a9cb2d1cd3f3e5c13dc33e15c9c4b8079f626e790e86ca211ab33b163b0942ffc90
7
+ data.tar.gz: b0286be1b1273b5f53390c022dad711cde8aeb41fdd546619da928fbfc18885a2a3feb7e6c2d54a5fe65321141729dc203c8388156241c6bec7ae7e2cb81e257
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ ## v0.3.2
2
+
3
+ * Support primary\_key option of belongs\_to association [#7](https://github.com/k0kubun/activerecord-precounter/pull/7)
4
+
5
+ ## v0.3.1
6
+
7
+ * Fix [#5](https://github.com/k0kubun/activerecord-precounter/pull/5) for ActiveRecord 5.0 (take 3)
8
+
9
+ ## v0.3.0
10
+
11
+ * Fix [#5](https://github.com/k0kubun/activerecord-precounter/pull/5) for ActiveRecord 5.0 (take 2)
12
+ * [breaking] Drop ActiveRecord 4.2 support
13
+
14
+ ## v0.2.3
15
+
16
+ * Fix count of scoped association [#5](https://github.com/k0kubun/activerecord-precounter/pull/5)
17
+
18
+ ## v0.2.2
19
+
20
+ * Fix unexpected subquery [#4](https://github.com/k0kubun/activerecord-precounter/pull/5)
21
+
22
+ ## v0.2.1
23
+
24
+ * Add support for counting scoped association
25
+ * Return empty array when target records don't exist
26
+
27
+ ## v0.2.0
28
+
29
+ * [breaking] Completely change interface
30
+
31
+ ## v0.1.0
32
+
33
+ * Initial release
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'activerecord', '>= 5'
25
25
  spec.add_development_dependency 'bundler'
26
26
  spec.add_development_dependency 'mysql2'
27
- spec.add_development_dependency 'postgres'
27
+ spec.add_development_dependency 'pg'
28
28
  spec.add_development_dependency 'rake'
29
29
  spec.add_development_dependency 'rspec'
30
30
  spec.add_development_dependency 'sqlite3'
@@ -26,21 +26,23 @@ module ActiveRecord
26
26
  )
27
27
  end
28
28
 
29
+ primary_key = reflection.inverse_of.association_primary_key.to_sym
30
+
29
31
  count_by_id = if reflection.has_scope?
30
32
  # ActiveRecord 5.0 unscopes #scope_for argument, so adding #where outside that:
31
33
  # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/reflection.rb#L314-L316
32
- reflection.scope_for(reflection.klass.unscoped).where(reflection.inverse_of.name => records.map(&:id)).group(
34
+ reflection.scope_for(reflection.klass.unscoped).where(reflection.inverse_of.name => records.map(&primary_key)).group(
33
35
  reflection.inverse_of.foreign_key
34
36
  ).count
35
37
  else
36
- reflection.klass.where(reflection.inverse_of.name => records.map(&:id)).group(
38
+ reflection.klass.where(reflection.inverse_of.name => records.map(&primary_key)).group(
37
39
  reflection.inverse_of.foreign_key
38
40
  ).count
39
41
  end
40
42
 
41
43
  writer = define_count_accessor(records.first, association_name)
42
44
  records.each do |record|
43
- record.public_send(writer, count_by_id.fetch(record.id, 0))
45
+ record.public_send(writer, count_by_id.fetch(record.public_send(primary_key), 0))
44
46
  end
45
47
  end
46
48
  records
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  class Precounter
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
5
5
  end
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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-07 00:00:00.000000000 Z
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: postgres
56
+ name: pg
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -118,6 +118,7 @@ files:
118
118
  - ".gitignore"
119
119
  - ".rspec"
120
120
  - ".travis.yml"
121
+ - CHANGELOG.md
121
122
  - Gemfile
122
123
  - LICENSE.txt
123
124
  - README.md