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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 318832502d533bdc4808c18673502e01d2d6328045d6584b2dfe50466bff7adb
4
- data.tar.gz: ef480667fe0aedd7abd18d56b38dd29562f3718777bda9cc71c3705d066fc684
3
+ metadata.gz: 0aa2f63c9f4f258d67ea8394f6cd7bade5bcdfa4bb8688b52797060224034e2d
4
+ data.tar.gz: 0211d9654d0bcde150cdaef99c44a69016a96ecf2f592c11b5c560b13a1b97a1
5
5
  SHA512:
6
- metadata.gz: 7594caeb737ca76c140c718d8cecc85080f3a7c3b21c9c547602b98f56630df389c17e299610a9452015f5d1222a3f80a97f6c61bde4072f137f4addcf1ceb23
7
- data.tar.gz: a02c3eac8e8f416c633961ff71e8cbe23c3193ca426ae80170436761d422a4ca1740c15fca08ca0ea46b0a09a213facef9a0a1e76d45ea10dae92d7b55555c39
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
- .joins(joins)
45
- .group(qualified_primary_key(pivot))
46
- .select(qualified_primary_key(pivot), qualified_column(pivot, instruction["pivot_attribute_name"]), "COUNT(*)")
47
- .to_sql
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Optic
4
4
  module Rails
5
- VERSION = "1.1.0"
5
+ VERSION = "1.2.0"
6
6
  end
7
7
  end
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.1.0
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-25 00:00:00.000000000 Z
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