active_record_query_fixer 0.0.4 → 0.0.5

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: 7627a28c325bb89b5b7e0f5b1498c69b828167fd6077dcc5093138bc2e66d6f4
4
- data.tar.gz: 94ea6b3827f3bfd4e986ac927ba48a804ca86d41e00321200568e170ad5355b3
3
+ metadata.gz: 19fa73e1ddacc9003ee2eb47d734a7352db57ba07cc3289058f59accb3f6c35f
4
+ data.tar.gz: dab480dc00323d18ea6e407514f0d5af914319eaed54a39e251d6198e8c25513
5
5
  SHA512:
6
- metadata.gz: 34b513778527ea0b76d912a2d7e9786aa5f63e6a0af40d80325a79d441c8bebdacdf21712dce56ce5efc08f5e3e01d3b09d4fc1199abfb641f37be9a1f24ee0e
7
- data.tar.gz: e4c1780d83ae0d4f5d3fd582c3979185d034dd584b3ec02b7d5ccb853cc51fe68dbd0c9c86a9fcd1a2104ffe8239233bba7b54f74e0c7ecdeb0a913f4bf897d1
6
+ metadata.gz: 71e5ca9135ba7667b3e7da108a9b2543116afa23e8ab1b50a0d0d1a37a291aba82859739c43d2cc1021d29a2466b60ce00633b7624c4a8c17265f97962aa66c9
7
+ data.tar.gz: af90fa1f50f0ef0edaa15e95543ec087a870ef0cef1ac79cfcac981eceb56f9a3c4492b3f3a58db7a01306b236f791642b9a3aff2ea554eed28252f52a29f6ac
@@ -13,13 +13,14 @@ class ActiveRecordQueryFixer
13
13
  end
14
14
 
15
15
  def fix
16
+ fix_reference_group if fix_reference_group?
16
17
  fix_order_group if fix_order_group?
17
18
  fix_order_select_distinct if fix_order_select_distinct?
18
19
  self
19
20
  end
20
21
 
21
22
  def fix_order_group
22
- @query = @query.group("#{@query.model.table_name}.#{@query.model.primary_key}")
23
+ @query = @query.group(@query.model.arel_table[@query.model.primary_key])
23
24
 
24
25
  @query.values[:order]&.each do |order|
25
26
  @query = @query.group(extract_table_and_column_from_expression(order))
@@ -40,6 +41,14 @@ class ActiveRecordQueryFixer
40
41
  self
41
42
  end
42
43
 
44
+ def fix_reference_group
45
+ @query = @query.group(@query.model.arel_table[@query.model.primary_key])
46
+
47
+ @query.values[:references].each do |reference|
48
+ @query = @query.group("#{reference}.id")
49
+ end
50
+ end
51
+
43
52
  private
44
53
 
45
54
  def extract_table_and_column_from_expression(order)
@@ -64,6 +73,10 @@ private
64
73
  def fix_order_select_distinct?
65
74
  @query.values[:distinct].present? && @query.values[:order].present?
66
75
  end
76
+
77
+ def fix_reference_group?
78
+ @query.values[:references].present? && @query.values[:group].present?
79
+ end
67
80
  end
68
81
 
69
82
  ActiveRecord::Relation.include ActiveRecordQueryFixer::RelationExtentions
@@ -1,3 +1,3 @@
1
1
  class ActiveRecordQueryFixer
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.0.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_query_fixer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-05 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for automatically added `.select` on a column used for `.distinct`
14
14
  or automatically adding `.group` for a column used for order.
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  version: '0'
46
46
  requirements: []
47
47
  rubyforge_project:
48
- rubygems_version: 2.7.6
48
+ rubygems_version: 2.7.7
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: A library for automatically added `.select` on a column used for `.distinct`