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 +4 -4
- data/lib/active_record_query_fixer.rb +14 -1
- data/lib/active_record_query_fixer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19fa73e1ddacc9003ee2eb47d734a7352db57ba07cc3289058f59accb3f6c35f
|
4
|
+
data.tar.gz: dab480dc00323d18ea6e407514f0d5af914319eaed54a39e251d6198e8c25513
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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
|
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
|
+
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-
|
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.
|
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`
|