arel-helpers 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arel-helpers/join_association.rb +39 -4
- data/lib/arel-helpers/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: e692ef35ca5dfd967971eeb47c87ef93b6ca21c142e03ecb29b608c1e8e533e0
|
4
|
+
data.tar.gz: 719115c3d5f7a9c86d89d6bc720e390906eac6a9d5b60d29c19bebe751aa8c5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 946f6a173a8a3da761ad79b9a416cc7b7871ba0ce879ecd0cb32b2348199c65109df1f7ebee1ec438bdf3cf443d840282935e97d56eed009ac54a31b79cb9d83
|
7
|
+
data.tar.gz: 346d3fcbe5be8208734ca9a35f47870531524d008f8e67d307912eb3582d134b2b51c5a721ff31b5488efb519ade8c6c7830db509aa38450280e764147974527
|
@@ -18,13 +18,15 @@ module ArelHelpers
|
|
18
18
|
# This method encapsulates that functionality and yields an intermediate object for chaining.
|
19
19
|
# It also allows you to use an outer join instead of the default inner via the join_type arg.
|
20
20
|
def join_association(table, association, join_type = Arel::Nodes::InnerJoin, options = {}, &block)
|
21
|
-
if
|
21
|
+
if version >= '5.2.1'
|
22
|
+
join_association_5_2_1(table, association, join_type, options, &block)
|
23
|
+
elsif version >= '5.2.0'
|
22
24
|
join_association_5_2(table, association, join_type, options, &block)
|
23
|
-
elsif
|
25
|
+
elsif version >= '5.0.0'
|
24
26
|
join_association_5_0(table, association, join_type, options, &block)
|
25
|
-
elsif
|
27
|
+
elsif version >= '4.2.0'
|
26
28
|
join_association_4_2(table, association, join_type, options, &block)
|
27
|
-
elsif
|
29
|
+
elsif version >= '4.1.0'
|
28
30
|
join_association_4_1(table, association, join_type, options, &block)
|
29
31
|
else
|
30
32
|
join_association_3_1(table, association, join_type, options, &block)
|
@@ -33,6 +35,10 @@ module ArelHelpers
|
|
33
35
|
|
34
36
|
private
|
35
37
|
|
38
|
+
def version
|
39
|
+
ActiveRecord::VERSION::STRING
|
40
|
+
end
|
41
|
+
|
36
42
|
def join_association_3_1(table, association, join_type, options = {})
|
37
43
|
aliases = options.fetch(:aliases, {})
|
38
44
|
associations = association.is_a?(Array) ? association : [association]
|
@@ -182,6 +188,35 @@ module ArelHelpers
|
|
182
188
|
end
|
183
189
|
end
|
184
190
|
|
191
|
+
def join_association_5_2_1(table, association, join_type, options = {})
|
192
|
+
aliases = options.fetch(:aliases, [])
|
193
|
+
associations = association.is_a?(Array) ? association : [association]
|
194
|
+
|
195
|
+
alias_tracker = ActiveRecord::Associations::AliasTracker.create(
|
196
|
+
table.connection, table.name, {}
|
197
|
+
)
|
198
|
+
|
199
|
+
join_dependency = ActiveRecord::Associations::JoinDependency.new(
|
200
|
+
table, table.arel_table, associations
|
201
|
+
)
|
202
|
+
|
203
|
+
constraints = join_dependency.join_constraints([], join_type, alias_tracker)
|
204
|
+
|
205
|
+
constraints.map do |join|
|
206
|
+
right = if block_given?
|
207
|
+
yield join.left.name.to_sym, join.right
|
208
|
+
else
|
209
|
+
join.right
|
210
|
+
end
|
211
|
+
|
212
|
+
if found_alias = find_alias(join.left.name, aliases)
|
213
|
+
join.left.table_alias = found_alias.name
|
214
|
+
end
|
215
|
+
|
216
|
+
join_type.new(join.left, right)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
185
220
|
private
|
186
221
|
|
187
222
|
def to_sql(node, table, binds)
|
data/lib/arel-helpers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|