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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c298c3d82954bcbdb17927662423bff146aeabb
|
4
|
+
data.tar.gz: 4d14515633cf34b0fddb9d53fe6cfcc62466ddf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|