active_record_aliased_joins 0.1.1 → 0.1.3

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: 42ecede644e2fa12c739f436ae2c4f20354c32c3906ddea61a1e23e03db43df9
4
- data.tar.gz: d1368eb855eb124084a71496790e750a14742d12bea096234979d1e1e30f27e9
3
+ metadata.gz: bc612630e193bf7a8d30dfa1ca31488616e8241caa294bd63bdabd50950cb6b4
4
+ data.tar.gz: cdc77df665f7c39bf2151308494671d2797e2acad37e5063a7f983821f12fdb3
5
5
  SHA512:
6
- metadata.gz: f225883cdab384457adb3e51b914ce21604f82b0d632101ae883eea05bc17ec53946883170c96f2730d5fb4916f3613245680200b5f99a54426246c3d4d24313
7
- data.tar.gz: c64a6f2e95fc744a991080c0e4c07524449cf684d25c344fc4c6836465ab6cfd4a955be7a0f3d08bfbb46bec5f683ee11ff17e70105a3292c2717b63cbac572a
6
+ metadata.gz: 633895395e681539bfb9491a967839b5d3f4031b12e62dd90c1dc17a918e396b41b09958089d7c20f002c35ae069e202d4028d9b730d792ddf6136d7503fc9e5
7
+ data.tar.gz: 8bcc0e7c26e63a0b210ad9f26750177957a7bfd16d5a133794fa02eab20c08f69fdabd5d031f795d0a85caf8501d9049cb11946310e0f774bb116d8ad12aa3bf
data/.rubocop.yml CHANGED
@@ -17,4 +17,7 @@ Metrics/MethodLength:
17
17
  Max: 20
18
18
 
19
19
  Metrics/AbcSize:
20
- Max: 40
20
+ Max: 40
21
+
22
+ Metrics/ClassLength:
23
+ Max: 200
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordAliasedJoins
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -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.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-20 00:00:00.000000000 Z
11
+ date: 2023-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord