eager_group 0.8.0 → 0.8.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: 516b00c6397d1a6b397b165687091079118a48ed39fc0afce4542d3cf4f7f481
4
- data.tar.gz: 9bf3083695c819003574f3971d2a592443320af92dc98c1ff36b302c87718889
3
+ metadata.gz: 5370e57578e725513b391777f1a86e3b1d7560bc596a08b005110d3220d43325
4
+ data.tar.gz: b4987065f8781190983f2b92a84db5ea7e248f43290763ba483d52ec472cb1e8
5
5
  SHA512:
6
- metadata.gz: 389265b557184c2d3f3c0207340c8bd65086a38fb8e0b2b168a4c14ed37f82b5bcb0ee89ab7a48da528bfbcf2174c1c89dcc0fd917eade1de9c184cad3238e9b
7
- data.tar.gz: 6e5e9bd946a9d333bda2087578ac47b98d57ab0cb8347adc9577f582124e1ca9a571fdddeaa28da48644aca0f9d0546f1ee323149742b2c0868d5d6c324354da
6
+ metadata.gz: 172290ed5e79c34139cdc35976f22e612e225e39f6b417f07f86696970f28969f058c59189e683d9ca299d5d61643dbdbf8220648889f7e4bbcb66cb30f68d7e
7
+ data.tar.gz: 91577037162ebb062b8939c02fc2aa66e4fdf1e891fb6e20ffd199d7e80879c38f20ae4fc4cc95ae32c7f16ab90377816ed42dc215dd0cd92fad9ce01f9450ea
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Next Release
2
2
 
3
+ ## 0.8.2 (09/22/2022)
4
+
5
+ * Add MIT-LICENSE
6
+
7
+ ## 0.8.1 (10/25/2019)
8
+
9
+ * Fix for `has_many :through`
10
+
3
11
  ## 0.8.0 (10/21/2019)
4
12
 
5
13
  * Support `has_and_belongs_to_many`
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 - 2022 Richard Huang (flyerhzm@gmail.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -31,28 +31,20 @@ 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
+ [
39
+ "#{reflection.through_reflection.name}.#{reflection.through_reflection.foreign_key}",
40
+ @klass.joins(reflection.name)
41
+ ]
42
+ else
43
+ [reflection.foreign_key, association_class]
44
+ end
45
+ aggregate_hash =
46
+ aggregate_hash.where(foreign_key => record_ids).where(polymophic_as_condition(reflection)).group(foreign_key)
47
+ .send(definition.aggregation_function, definition.column_name)
56
48
  if definition.need_load_object
57
49
  aggregate_objects = reflection.klass.find(aggregate_hash.values).each_with_object({}) { |o, h| h[o.id] = o }
58
50
  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.2'
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-21 00:00:00.000000000 Z
11
+ date: 2022-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -134,6 +134,7 @@ files:
134
134
  - ".travis.yml"
135
135
  - CHANGELOG.md
136
136
  - Gemfile
137
+ - MIT-LICENSE
137
138
  - README.md
138
139
  - Rakefile
139
140
  - benchmark.rb
@@ -149,7 +150,7 @@ homepage: https://github.com/flyerhzm/eager_group
149
150
  licenses:
150
151
  - MIT
151
152
  metadata: {}
152
- post_install_message:
153
+ post_install_message:
153
154
  rdoc_options: []
154
155
  require_paths:
155
156
  - lib
@@ -164,8 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
165
  - !ruby/object:Gem::Version
165
166
  version: '0'
166
167
  requirements: []
167
- rubygems_version: 3.0.3
168
- signing_key:
168
+ rubygems_version: 3.3.7
169
+ signing_key:
169
170
  specification_version: 4
170
171
  summary: Fix n+1 aggregate sql functions
171
172
  test_files: []