activerecord_where_assoc 1.1.3 → 1.1.5

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: fd0fae20ed7a2ae8fac19fda0df7f70b9b6a842a6519684c66c571dbf2f57732
4
- data.tar.gz: f570a564494a52517dde7aad62c79b571ab3d1e49d651f32ac2bb86b301fa4f6
3
+ metadata.gz: 366ed8e028f8ed692b13cd8c487385ec380c57f41ce51edcd3370a2412ffe8f3
4
+ data.tar.gz: c6d2c1b2111cda267e7c5c6555692317ad0188cd748972f262acbdcba02eee7e
5
5
  SHA512:
6
- metadata.gz: 240832561dd8eb5cc93ff3ebc239a0aedf8f9f79520a6404ffe6ac8f9d1b2cacd5f0057d85066ed889b62f16b5e85125acb8b943c91fa72ab0450a366d7d7569
7
- data.tar.gz: 060f842df0bd69b72ac0e6f0a64ef222b347047d693046abe83a9bfdd6797109e202bcccc32f75a3e7bc4349f1b5a50c94982102571a699b113e65331ebca459
6
+ metadata.gz: 1dd9b3955c50ec5ed37ca032b7aa20d93eac2ab035a914e1032efe1527a7b86cd33cd3832c3fa68010bfafef4780f2dfba473e99fa0f089bb3649c8aed578c27
7
+ data.tar.gz: 6bae922127f45e21c2484c3ef28f0d47512cb1d2cc0b1e94a97a628277698eceb04595b3f96759d367be1e94e4441ad72e8e2901aabf44169994989579b68d00
data/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # Unreleased
2
2
 
3
+ # 1.1.5 - 2024-05-18
4
+
5
+ * Add compatibility for Rails 7.2
6
+
7
+ # 1.1.4 - 2023-10-10
8
+
9
+ * Add compatibility for Rails 7.1
10
+
3
11
  # 1.1.3 - 2022-08-16
4
12
 
5
13
  * Add support for associations defined on abstract models
6
14
 
7
15
  # 1.1.2 - 2020-12-24
8
16
 
9
- * Add compatiblity for Rails 6.1
17
+ * Add compatibility for Rails 6.1
10
18
 
11
19
  # 1.1.1 - 2020-04-13
12
20
 
data/EXAMPLES.md CHANGED
@@ -1,4 +1,3 @@
1
- SELECT "users".* FROM "users"
2
1
  Here are some example usages of the gem, along with the generated SQL.
3
2
 
4
3
  Each of those methods can be chained with scoping methods, so they can be used on `Post`, `my_user.posts`, `Post.where('hello')` or inside a scope. Note that for the `*_sql` variants, those should preferably be used on classes only, because otherwise, it could be confusing for a reader.
@@ -72,7 +72,7 @@ module ActiveRecordWhereAssoc
72
72
  end
73
73
  end
74
74
 
75
- if ActiveRecord.gem_version >= Gem::Version.new("4.2")
75
+ if ActiveRecord.gem_version >= Gem::Version.new("4.2") && ActiveRecord.gem_version < Gem::Version.new("7.2.0.alpha")
76
76
  def self.normalize_association_name(association_name)
77
77
  association_name.to_s
78
78
  end
@@ -91,5 +91,15 @@ module ActiveRecordWhereAssoc
91
91
  reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
92
92
  end
93
93
  end
94
+
95
+ if ActiveRecord.gem_version >= Gem::Version.new("7.1.0.alpha")
96
+ def self.null_relation?(reflection)
97
+ reflection.null_relation?
98
+ end
99
+ else
100
+ def self.null_relation?(reflection)
101
+ reflection.is_a?(ActiveRecord::NullRelation)
102
+ end
103
+ end
94
104
  end
95
105
  end
@@ -13,7 +13,7 @@ module ActiveRecordWhereAssoc
13
13
  # => "EXISTS (SELECT... *relation1*) OR EXISTS (SELECT... *relation2*)"
14
14
  def self.sql_for_any_exists(relations)
15
15
  relations = [relations] unless relations.is_a?(Array)
16
- relations = relations.reject { |rel| rel.is_a?(ActiveRecord::NullRelation) }
16
+ relations = relations.reject { |rel| ActiveRecordCompat.null_relation?(rel) }
17
17
  sqls = relations.map { |rel| "EXISTS (#{rel.select('1').to_sql})" }
18
18
  if sqls.size > 1
19
19
  "(#{sqls.join(" OR ")})" # Parens needed when embedding the sql in a `where`, because the OR could make things wrong
@@ -33,7 +33,7 @@ module ActiveRecordWhereAssoc
33
33
  # => "SUM((SELECT... *relation1*)) + SUM((SELECT... *relation2*))"
34
34
  def self.sql_for_sum_of_counts(relations)
35
35
  relations = [relations] unless relations.is_a?(Array)
36
- relations = relations.reject { |rel| rel.is_a?(ActiveRecord::NullRelation) }
36
+ relations = relations.reject { |rel| ActiveRecordCompat.null_relation?(rel) }
37
37
  # Need the double parentheses
38
38
  relations.map { |rel| "SUM((#{rel.to_sql}))" }.join(" + ").presence || "0"
39
39
  end
@@ -85,7 +85,7 @@ module ActiveRecordWhereAssoc
85
85
  end
86
86
 
87
87
  nested_relations = relations_on_association(record_class, association_names, given_conditions, options, deepest_scope_mod, NestWithSumBlock)
88
- nested_relations = nested_relations.reject { |rel| rel.is_a?(ActiveRecord::NullRelation) }
88
+ nested_relations = nested_relations.reject { |rel| ActiveRecordCompat.null_relation?(rel) }
89
89
  nested_relations.map { |nr| "COALESCE((#{nr.to_sql}), 0)" }.join(" + ").presence || "0"
90
90
  end
91
91
 
@@ -334,7 +334,7 @@ module ActiveRecordWhereAssoc
334
334
  end
335
335
 
336
336
  # No need to do transformations if this is already a NullRelation
337
- return current_scope if current_scope.is_a?(ActiveRecord::NullRelation)
337
+ return current_scope if ActiveRecordCompat.null_relation?(current_scope)
338
338
 
339
339
  current_scope = current_scope.limit(1) if reflection.macro == :has_one
340
340
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordWhereAssoc
4
- VERSION = "1.1.3".freeze
4
+ VERSION = "1.1.5".freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_where_assoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Handfield Lapointe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-16 00:00:00.000000000 Z
11
+ date: 2024-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.15'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.6'
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '1.15'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.6'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: minitest
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -190,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
196
  - !ruby/object:Gem::Version
191
197
  version: '0'
192
198
  requirements: []
193
- rubygems_version: 3.3.7
199
+ rubygems_version: 3.4.10
194
200
  signing_key:
195
201
  specification_version: 4
196
202
  summary: Make ActiveRecord do conditions on your associations