active_record_aliased_joins 0.1.1 → 0.1.3
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 +4 -4
- data/.rubocop.yml +4 -1
- data/lib/active_record_aliased_joins/version.rb +1 -1
- data/lib/active_record_aliased_joins.rb +15 -11
- 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: bc612630e193bf7a8d30dfa1ca31488616e8241caa294bd63bdabd50950cb6b4
|
4
|
+
data.tar.gz: cdc77df665f7c39bf2151308494671d2797e2acad37e5063a7f983821f12fdb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 633895395e681539bfb9491a967839b5d3f4031b12e62dd90c1dc17a918e396b41b09958089d7c20f002c35ae069e202d4028d9b730d792ddf6136d7503fc9e5
|
7
|
+
data.tar.gz: 8bcc0e7c26e63a0b210ad9f26750177957a7bfd16d5a133794fa02eab20c08f69fdabd5d031f795d0a85caf8501d9049cb11946310e0f774bb116d8ad12aa3bf
|
data/.rubocop.yml
CHANGED
@@ -20,18 +20,18 @@ module ActiveRecordAliasedJoins
|
|
20
20
|
|
21
21
|
# Module to add joins_with_alias support to ActiveRecord::Base
|
22
22
|
module JoinWithAlias
|
23
|
-
def joins_with_alias(association_name, alias_name)
|
23
|
+
def joins_with_alias(association_name, alias_name, join_klass = Arel::Nodes::InnerJoin)
|
24
24
|
reflection = _reflect_on_association(association_name.to_s)
|
25
25
|
raise ActiveRecord::AssociationNotFoundError unless reflection
|
26
26
|
|
27
27
|
source_joins =
|
28
28
|
case reflection
|
29
29
|
when ActiveRecord::Reflection::HasManyReflection, ActiveRecord::Reflection::HasOneReflection
|
30
|
-
join_with_alias_has_many_has_one(reflection, association_name, alias_name)
|
30
|
+
join_with_alias_has_many_has_one(reflection, association_name, alias_name, join_klass)
|
31
31
|
when ActiveRecord::Reflection::BelongsToReflection
|
32
|
-
join_with_alias_belongs_to(reflection, association_name, alias_name)
|
32
|
+
join_with_alias_belongs_to(reflection, association_name, alias_name, join_klass)
|
33
33
|
when ActiveRecord::Reflection::ThroughReflection, ActiveRecord::Reflection::HasAndBelongsToManyReflection
|
34
|
-
join_with_alias_through(reflection, association_name, alias_name)
|
34
|
+
join_with_alias_through(reflection, association_name, alias_name, join_klass)
|
35
35
|
else
|
36
36
|
raise UnsupportedReflectionError, reflection
|
37
37
|
end
|
@@ -39,23 +39,27 @@ module ActiveRecordAliasedJoins
|
|
39
39
|
joins(source_joins.join_sources)
|
40
40
|
end
|
41
41
|
|
42
|
+
def left_joins_with_alias(association_name, alias_name)
|
43
|
+
joins_with_alias(association_name, alias_name, Arel::Nodes::OuterJoin)
|
44
|
+
end
|
45
|
+
|
42
46
|
private
|
43
47
|
|
44
|
-
def join_with_alias_has_many_has_one(reflection, _association_name, alias_name)
|
48
|
+
def join_with_alias_has_many_has_one(reflection, _association_name, alias_name, join_klass = Nodes::InnerJoin)
|
45
49
|
s = arel_table
|
46
50
|
related_klass = reflection.klass
|
47
51
|
r = related_klass.arel_table.alias(alias_name)
|
48
|
-
s.join(r).on(s[primary_key.to_sym].eq(r[reflection.foreign_key.to_sym]))
|
52
|
+
s.join(r, join_klass).on(s[primary_key.to_sym].eq(r[reflection.foreign_key.to_sym]))
|
49
53
|
end
|
50
54
|
|
51
|
-
def join_with_alias_belongs_to(reflection, _association_name, alias_name)
|
55
|
+
def join_with_alias_belongs_to(reflection, _association_name, alias_name, join_klass = Nodes::InnerJoin)
|
52
56
|
s = arel_table
|
53
57
|
related_klass = reflection.klass
|
54
58
|
r = related_klass.arel_table.alias(alias_name)
|
55
|
-
s.join(r).on(s[reflection.foreign_key.to_sym].eq(r[primary_key.to_sym]))
|
59
|
+
s.join(r, join_klass).on(s[reflection.foreign_key.to_sym].eq(r[related_klass.primary_key.to_sym]))
|
56
60
|
end
|
57
61
|
|
58
|
-
def join_with_alias_through(reflection, association_name, alias_name)
|
62
|
+
def join_with_alias_through(reflection, association_name, alias_name, join_klass = Nodes::InnerJoin)
|
59
63
|
s = arel_table
|
60
64
|
related_klass = reflection.klass
|
61
65
|
r = related_klass.arel_table.alias(alias_name)
|
@@ -65,8 +69,8 @@ module ActiveRecordAliasedJoins
|
|
65
69
|
t = t_klass.arel_table
|
66
70
|
t_r_reflection = t_klass._reflect_on_association(association_name.to_s.singularize)
|
67
71
|
|
68
|
-
s.join(t).on(s[primary_key.to_sym].eq(t[s_t_reflection.foreign_key.to_sym]))
|
69
|
-
.join(r).on(t[t_r_reflection.foreign_key.to_sym].eq(r[related_klass.primary_key.to_sym]))
|
72
|
+
s.join(t, join_klass).on(s[primary_key.to_sym].eq(t[s_t_reflection.foreign_key.to_sym]))
|
73
|
+
.join(r, join_klass).on(t[t_r_reflection.foreign_key.to_sym].eq(r[related_klass.primary_key.to_sym]))
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_aliased_joins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Gebhardt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|