active_record_aliased_joins 0.1.0 → 0.1.2

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: 327d19007378e55ab5a74fe808ac4ebd870523427037e3635c4bcf63b767ef9e
4
- data.tar.gz: bbc566087d0ea1cf1c3b9529c4cc6f0d4f2f74202016cb4d567bb907c0625d68
3
+ metadata.gz: 98d045644c3e8aae0c9d63c1e85555a1cee684190313c190fc5cd091c99898f6
4
+ data.tar.gz: bd247d692d109a8a4140fa9d29efcea75b8dbbf512e7d7accf81f322ab69de22
5
5
  SHA512:
6
- metadata.gz: 5235bb6c4b9e9328917e882554cb0e0b1772105da63128ccb82fcf85cb1217ed439b546687d43e4b7a19f161996a32415a17f3fa1b707834e2241d3468542d5c
7
- data.tar.gz: 510ebf8d7a078814189e69ea9cc02ef006363836be4286cd61a18e8f65624f9dd8e81ace98776420257502f24f026e881688a1966d637cfbb6c4aa785e524b82
6
+ metadata.gz: d6686baf5c1d6dec938a4fb8f77dd06df634e064f8eae9d5e2587b1ab3772bbb03f50e6d9809b7675ef4372024c822d0b58d0b45beafd3a4db581de7b411a9b9
7
+ data.tar.gz: 37025699218bbfce0319f6c2750731f4af082c83f7288f3acc2b97cc3887e6255b86b44ba6c908fa290f4a2434a22a6c1f2b9a0a2b9aad3bf5456330d95cd3e9
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.0'
4
+ VERSION = '0.1.2'
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[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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Larry Gebhardt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-22 00:00:00.000000000 Z
11
+ date: 2023-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord