through_hierarchy 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74f01013ac5a0df1c24c2ca7202d6de47936dcff
4
- data.tar.gz: 1c2e2a79defb580b6449e90535f6683725996497
3
+ metadata.gz: 4c298c3d82954bcbdb17927662423bff146aeabb
4
+ data.tar.gz: 4d14515633cf34b0fddb9d53fe6cfcc62466ddf0
5
5
  SHA512:
6
- metadata.gz: 5026fbd509012ffd95864c8732fe08ca37dc398ea8ef36688f7d0cd76cdd42082aaae32b8022a02ae9725d5b98482cbacd22ef8ce150e3c8cfc4f561bfae1416
7
- data.tar.gz: 8b246b81fedf869e249b66dc9074c0bb922264bd840914c36b27f7a3209c7c4868330d9f0b10c5c68c86f91d5dc1fc61fb0c8c83f0d12aa5e792b5d62ca3a0ca
6
+ metadata.gz: 6cedbd9ab437b3bab6e2ffb882679b07a053f028ee1452b5b0dca985a4abb63a91e2ebac478435c0b41e6b7eaaddbfb6a8c53cc0f6035200b9650cf458955129
7
+ data.tar.gz: abf0b810b772afc73d3bc7dd853f89a68f05ae2a61a6bdb5e0912eb95bf85a8260288da0b9c3f2d3d85ea682851e719420e76a92fa86254657effced0642aa59
@@ -10,10 +10,7 @@ module ThroughHierarchy
10
10
  private
11
11
 
12
12
  def get_joins
13
- arel = @associated.join_best_rank
14
- result = @model.joins(arel.join_sources).order(arel.orders)
15
- arel.constraints.each{|cc| result = result.where(cc)}
16
- return result
13
+ @associated.join_best_rank
17
14
  end
18
15
 
19
16
  end
@@ -22,10 +22,7 @@ module ThroughHierarchy
22
22
  end
23
23
 
24
24
  def get_joins
25
- arel = @associated.join_best_rank(group_by: @uniq)
26
- result = @model.joins(arel.join_sources).order(arel.orders)
27
- arel.constraints.each{|cc| result = result.where(cc)}
28
- return result
25
+ @associated.join_best_rank(group_by: @uniq)
29
26
  end
30
27
 
31
28
  end
@@ -93,16 +93,22 @@ module ThroughHierarchy
93
93
  # Join @model to @source only on best hierarchy matches
94
94
  ### FASTER METHOD: join source to source alias on source.rank < alias.rank where alias does not exist
95
95
  # This performs OK.
96
+ # TODO: return arel once we know how to use the binds properly
96
97
  def join_best_rank(group_by: nil)
97
98
  better_rank = spawn(@source.alias("better_hierarchy"))
98
- @model.joins(@hierarchy).arel.
99
+ join_condition_array = [
100
+ better_rank.filters,
101
+ better_rank.hierarchy_rank.lt(hierarchy_rank)
102
+ ]
103
+ join_condition_array << better_rank.source[group_by].eq(@source[group_by]) if group_by.present?
104
+ arel = @model.arel_table.
99
105
  join(@source).on(filters).
100
106
  join(better_rank.source, Arel::Nodes::OuterJoin).
101
- on(
102
- better_rank.filters.
103
- and(better_rank.hierarchy_rank.lt(hierarchy_rank))
104
- ).
107
+ on(and_conditions(join_condition_array)).
105
108
  where(better_rank.source[:id].eq(nil))
109
+ result = @model.joins(@hierarchy).joins(arel.join_sources).order(arel.orders)
110
+ arel.constraints.each{|cc| result = result.where(cc)}
111
+ return result
106
112
  end
107
113
 
108
114
  # # TODO: generate this dynamically based on existing columns and selects
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: through_hierarchy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Schwartz