where_exists 3.1.0 → 3.2.1
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/lib/where_exists/version.rb +1 -1
- data/lib/where_exists.rb +12 -5
- data/test/has_many_through_conditions_test.rb +41 -0
- data/test/test_helper.rb +2 -5
- metadata +14 -14
- data/test/db/test.db +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7418a9047cf21e0b2ba7704220f6102c3e2c830096e6885a3c163ca66107af2f
|
|
4
|
+
data.tar.gz: 6c4d58b3e9bf1090ab6c6a6f1e6c5c3924157e0b86cee6072c85f90c4bae4ba6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f9d348e8bed4be3c46d0c1d01b1dc4104349b2e09a2b2a8674c15b41493d3e456049834770b36a8a2ba0c77a0845fc53ce95d840e462db459ae7f09e08c7318
|
|
7
|
+
data.tar.gz: f06abf232e76ee00b2e3f048e41285168fffbeb34106713bc358d349a306576b0e3ad671c32fcbb8f23bcb39522e399b96737e4b7233d179e0789096097d27de
|
data/lib/where_exists/version.rb
CHANGED
data/lib/where_exists.rb
CHANGED
|
@@ -105,7 +105,8 @@ module WhereExists
|
|
|
105
105
|
next_association = {
|
|
106
106
|
association: association.source_reflection,
|
|
107
107
|
params: where_parameters,
|
|
108
|
-
next_association: next_association
|
|
108
|
+
next_association: next_association,
|
|
109
|
+
scope: association.scope
|
|
109
110
|
}
|
|
110
111
|
association = association.through_reflection
|
|
111
112
|
|
|
@@ -125,7 +126,7 @@ module WhereExists
|
|
|
125
126
|
end
|
|
126
127
|
end
|
|
127
128
|
|
|
128
|
-
association_scope =
|
|
129
|
+
association_scope = association.scope
|
|
129
130
|
|
|
130
131
|
associated_model = association.klass
|
|
131
132
|
|
|
@@ -207,12 +208,18 @@ module WhereExists
|
|
|
207
208
|
end
|
|
208
209
|
|
|
209
210
|
def loop_nested_association(query, next_association = {}, nested = false, &block)
|
|
211
|
+
scope = next_association[:scope] || -> { self }
|
|
212
|
+
block ||= ->(it) { it }
|
|
213
|
+
block_with_scope =
|
|
214
|
+
lambda do |it|
|
|
215
|
+
block.call(it.instance_exec(&scope))
|
|
216
|
+
end
|
|
210
217
|
str = query.klass.build_exists_string(
|
|
211
218
|
next_association[:association].name,
|
|
212
219
|
*[
|
|
213
220
|
*next_association[:params]
|
|
214
|
-
],
|
|
215
|
-
&
|
|
221
|
+
].compact,
|
|
222
|
+
&block_with_scope
|
|
216
223
|
)
|
|
217
224
|
|
|
218
225
|
if next_association[:next_association] && next_association[:next_association][:association]
|
|
@@ -222,7 +229,7 @@ module WhereExists
|
|
|
222
229
|
next_association[:association],
|
|
223
230
|
next_association[:next_association],
|
|
224
231
|
true,
|
|
225
|
-
&
|
|
232
|
+
&block_with_scope
|
|
226
233
|
)}))"
|
|
227
234
|
end
|
|
228
235
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
ActiveRecord::Migration.create_table :posts, :force => true do |t|
|
|
4
|
+
t.boolean :archived, default: false, null: false
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
ActiveRecord::Migration.create_table :comments, :force => true do |t|
|
|
8
|
+
t.integer :post_id
|
|
9
|
+
t.integer :commentator_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
ActiveRecord::Migration.create_table :commentators, :force => true do |t|
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Post < ActiveRecord::Base
|
|
16
|
+
has_many :comments
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Comment < ActiveRecord::Base
|
|
20
|
+
belongs_to :post
|
|
21
|
+
belongs_to :commentator
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Commentator < ActiveRecord::Base
|
|
25
|
+
has_many :comments
|
|
26
|
+
has_many :posts, -> { where(archived: false) }, through: :comments
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class HasManyThroughConditionsTest < Minitest::Test
|
|
30
|
+
def test_where_exists
|
|
31
|
+
post = Post.create!
|
|
32
|
+
archived_post = Post.create! archived: true
|
|
33
|
+
|
|
34
|
+
commentator = Commentator.create! posts: [post]
|
|
35
|
+
commentator2 = Commentator.create! posts: [archived_post]
|
|
36
|
+
commentator3 = Commentator.create!
|
|
37
|
+
|
|
38
|
+
assert_equal [commentator], Commentator.where_exists(:posts).to_a # fail: also includes commentator2
|
|
39
|
+
assert_equal [commentator2, commentator3], Commentator.where_not_exists(:posts).to_a # fail: does not include commentator2
|
|
40
|
+
end
|
|
41
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -13,8 +13,5 @@ else
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
ActiveRecord::Base.time_zone_aware_attributes = true
|
|
16
|
-
|
|
17
|
-
ActiveRecord::Base.
|
|
18
|
-
:adapter => 'sqlite3',
|
|
19
|
-
:database => File.dirname(__FILE__) + '/db/test.db'
|
|
20
|
-
)
|
|
16
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
|
17
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: where_exists
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1
|
|
4
|
+
version: 3.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eugene Zolotarev
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -19,7 +19,7 @@ dependencies:
|
|
|
19
19
|
version: '5.2'
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '8.
|
|
22
|
+
version: '8.2'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -29,7 +29,7 @@ dependencies:
|
|
|
29
29
|
version: '5.2'
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '8.
|
|
32
|
+
version: '8.2'
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: sqlite3
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -114,19 +114,19 @@ files:
|
|
|
114
114
|
- lib/where_exists/version.rb
|
|
115
115
|
- test/belongs_to_polymorphic_test.rb
|
|
116
116
|
- test/belongs_to_test.rb
|
|
117
|
-
- test/db/test.db
|
|
118
117
|
- test/documentation_test.rb
|
|
119
118
|
- test/has_and_belongs_to_many.rb
|
|
120
119
|
- test/has_many_polymorphic_test.rb
|
|
121
120
|
- test/has_many_test.rb
|
|
122
121
|
- test/has_many_through_belongs_to_test.rb
|
|
122
|
+
- test/has_many_through_conditions_test.rb
|
|
123
123
|
- test/has_many_through_test.rb
|
|
124
124
|
- test/test_helper.rb
|
|
125
125
|
homepage: http://github.com/eugzol/where_exists
|
|
126
126
|
licenses:
|
|
127
127
|
- MIT
|
|
128
128
|
metadata: {}
|
|
129
|
-
post_install_message:
|
|
129
|
+
post_install_message:
|
|
130
130
|
rdoc_options: []
|
|
131
131
|
require_paths:
|
|
132
132
|
- lib
|
|
@@ -141,18 +141,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
141
141
|
- !ruby/object:Gem::Version
|
|
142
142
|
version: '0'
|
|
143
143
|
requirements: []
|
|
144
|
-
rubygems_version: 3.
|
|
145
|
-
signing_key:
|
|
144
|
+
rubygems_version: 3.5.20
|
|
145
|
+
signing_key:
|
|
146
146
|
specification_version: 4
|
|
147
147
|
summary: "#where_exists extension of ActiveRecord"
|
|
148
148
|
test_files:
|
|
149
|
-
- test/documentation_test.rb
|
|
150
149
|
- test/belongs_to_polymorphic_test.rb
|
|
151
150
|
- test/belongs_to_test.rb
|
|
151
|
+
- test/documentation_test.rb
|
|
152
|
+
- test/has_and_belongs_to_many.rb
|
|
152
153
|
- test/has_many_polymorphic_test.rb
|
|
153
|
-
- test/
|
|
154
|
+
- test/has_many_test.rb
|
|
155
|
+
- test/has_many_through_belongs_to_test.rb
|
|
156
|
+
- test/has_many_through_conditions_test.rb
|
|
154
157
|
- test/has_many_through_test.rb
|
|
155
158
|
- test/test_helper.rb
|
|
156
|
-
- test/has_many_through_belongs_to_test.rb
|
|
157
|
-
- test/has_and_belongs_to_many.rb
|
|
158
|
-
- test/has_many_test.rb
|
data/test/db/test.db
DELETED
|
Binary file
|