optic-rails 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/optic/rails.rb +25 -5
- data/lib/optic/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aa2f63c9f4f258d67ea8394f6cd7bade5bcdfa4bb8688b52797060224034e2d
|
4
|
+
data.tar.gz: 0211d9654d0bcde150cdaef99c44a69016a96ecf2f592c11b5c560b13a1b97a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c211a4e662524ac0db1b2f858603de478d57b074a0959904f8a5142b5e56d12cc89d21aa653bf7509247132a2da5c803f34b6d51eacd122443203dc0739ae6d
|
7
|
+
data.tar.gz: 245695dd27b14e22afbdbd4aa5df1f08e0ee8f0635ccbe85aea7eacf98043958412414c48846001a13d4e22628c6c13b651232a198388eb6a2f84a2813b521c2
|
data/lib/optic/rails.rb
CHANGED
@@ -37,14 +37,34 @@ module Optic
|
|
37
37
|
|
38
38
|
query =
|
39
39
|
if pivot_name = instruction["pivot"]
|
40
|
+
# TODO this is a terrible hack to extract zero-valued pivot
|
41
|
+
# instances. The right thing to do is select from the pivot
|
42
|
+
# table and LEFT OUTER JOIN to the entity table, which results
|
43
|
+
# in a much simpler query, but it means we have to rewrite the
|
44
|
+
# pathfinding logic in the server to find paths using has_many
|
45
|
+
# associations instead of belongs_to associations, which might
|
46
|
+
# be less accurate for a bunch of reasons. For now, we're doing
|
47
|
+
# an INNER JOIN selecting from the entity table and then
|
48
|
+
# selecting every possible pivot value as a UNION, throwing out
|
49
|
+
# the duplicates.
|
40
50
|
pivot = pivot_name.constantize
|
41
51
|
join_path = instruction["join_path"]
|
42
52
|
joins = join_path.reverse.map(&:to_sym).inject { |acc, elt| { elt => acc } }
|
43
|
-
entity
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
join_select = entity
|
54
|
+
.joins(joins)
|
55
|
+
.group(qualified_primary_key(pivot))
|
56
|
+
.select(qualified_primary_key(pivot), qualified_column(pivot, instruction["pivot_attribute_name"]), "COUNT(*)")
|
57
|
+
.to_sql
|
58
|
+
|
59
|
+
instance_select = pivot
|
60
|
+
.select(qualified_primary_key(pivot), qualified_column(pivot, instruction["pivot_attribute_name"]), "0 as count")
|
61
|
+
.to_sql
|
62
|
+
|
63
|
+
union_sql = <<~"SQL"
|
64
|
+
SELECT "pivot_values"."id", "pivot_values"."name", MAX("pivot_values"."count") AS count
|
65
|
+
FROM (#{join_select} UNION ALL #{instance_select}) AS pivot_values
|
66
|
+
GROUP BY "pivot_values"."id", "pivot_values"."name"
|
67
|
+
SQL
|
48
68
|
else
|
49
69
|
entity.select("COUNT(*)").to_sql
|
50
70
|
end
|
data/lib/optic/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optic-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Vaynshtok
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: action_cable_client
|