eager_group 0.8.0 → 0.8.1

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: 516b00c6397d1a6b397b165687091079118a48ed39fc0afce4542d3cf4f7f481
4
- data.tar.gz: 9bf3083695c819003574f3971d2a592443320af92dc98c1ff36b302c87718889
3
+ metadata.gz: 88912c5696afe9332d53ac15b2365d2e2d7112391672a2cba5db62012876a138
4
+ data.tar.gz: a18a2d21cd4299a68774f3dbb62556c71f3096b3ebac28bebf7a767a875fc00f
5
5
  SHA512:
6
- metadata.gz: 389265b557184c2d3f3c0207340c8bd65086a38fb8e0b2b168a4c14ed37f82b5bcb0ee89ab7a48da528bfbcf2174c1c89dcc0fd917eade1de9c184cad3238e9b
7
- data.tar.gz: 6e5e9bd946a9d333bda2087578ac47b98d57ab0cb8347adc9577f582124e1ca9a571fdddeaa28da48644aca0f9d0546f1ee323149742b2c0868d5d6c324354da
6
+ metadata.gz: af269ea9b3be9f9a613f56cf14e52a7b183b6d041583f02aa88945f65150f98147ed7271523b9f8ec0d36c622f42ae257f7137e9cf842b381f11cbd7cd6e50bf
7
+ data.tar.gz: 2878aaefb0b9420b13531927cd46ad47894954c2999fe81d9bf853d7f2255ae97b42df8e56c43a840b5812d71ed1f535c391ccf605fbed99f08ed0769959eab8
@@ -1,5 +1,9 @@
1
1
  # Next Release
2
2
 
3
+ ## 0.8.1 (10/25/2019)
4
+
5
+ * Fix for `has_many :through`
6
+
3
7
  ## 0.8.0 (10/21/2019)
4
8
 
5
9
  * Support `has_and_belongs_to_many`
@@ -31,28 +31,18 @@ module EagerGroup
31
31
  association_class = reflection.klass
32
32
  association_class = association_class.instance_exec(*arguments, &definition.scope) if definition.scope
33
33
 
34
- if reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
35
- foreign_key = "#{reflection.join_table}.#{reflection.foreign_key}"
36
- aggregate_hash =
37
- @klass.joins(reflection.name).where(foreign_key => record_ids).where(
38
- polymophic_as_condition(reflection)
39
- )
40
- .group(foreign_key)
41
- .send(definition.aggregation_function, definition.column_name)
42
- elsif reflection.through_reflection
43
- foreign_key = "#{reflection.through_reflection.name}.#{reflection.through_reflection.foreign_key}"
44
- aggregate_hash =
45
- association_class.joins(reflection.through_reflection.name).where(foreign_key => record_ids).where(
46
- polymophic_as_condition(reflection.through_reflection)
47
- )
48
- .group(foreign_key)
49
- .send(definition.aggregation_function, definition.column_name)
50
- else
51
- aggregate_hash =
52
- association_class.where(reflection.foreign_key => record_ids).where(polymophic_as_condition(reflection))
53
- .group(reflection.foreign_key)
54
- .send(definition.aggregation_function, definition.column_name)
55
- end
34
+ foreign_key, aggregate_hash =
35
+ if reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
36
+ ["#{reflection.join_table}.#{reflection.foreign_key}", @klass.joins(reflection.name)]
37
+ elsif reflection.through_reflection
38
+ ["#{reflection.through_reflection.name}.#{reflection.through_reflection.foreign_key}", @klass.joins(reflection.name)]
39
+ else
40
+ [reflection.foreign_key, association_class]
41
+ end
42
+ aggregate_hash = aggregate_hash.where(foreign_key => record_ids)
43
+ .where(polymophic_as_condition(reflection))
44
+ .group(foreign_key)
45
+ .send(definition.aggregation_function, definition.column_name)
56
46
  if definition.need_load_object
57
47
  aggregate_objects = reflection.klass.find(aggregate_hash.values).each_with_object({}) { |o, h| h[o.id] = o }
58
48
  aggregate_hash.keys.each { |key| aggregate_hash[key] = aggregate_objects[aggregate_hash[key]] }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EagerGroup
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eager_group
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-21 00:00:00.000000000 Z
11
+ date: 2019-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord