ree_lib 1.0.59 → 1.0.60
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/Gemfile.lock +1 -1
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/association.rb +17 -31
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/load_agg_spec.rb +41 -0
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/ree_dao_load_agg_test.rb +8 -0
- data/lib/ree_lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77d773db4104deb076fe0ea9d9aa6b8e0fd1218d71731e6d51a70a50be09d569
|
4
|
+
data.tar.gz: ac943abd83280ff44db19e50991e1ca51aa92cd1f140ccaa9e82cf706fc9dc8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb4b4567e977e12c59f5246f819dcba9702ccb77fb5e776584f193f6cff18c14d4e7e40d75c0377b0fc905720936f0feb888e2e953b288466f7d777ed7bd633
|
7
|
+
data.tar.gz: 26ee7d50cf9e346c4cb9614832282d586d0ac767dcd0b65bdb056511ed2e3058f5d1186003e6f30b89a9a661768c7b7153e4d2a3f079185b441f9b7ca5582485
|
data/Gemfile.lock
CHANGED
@@ -160,32 +160,19 @@ module ReeDao
|
|
160
160
|
root_ids = list.map(&:id).uniq
|
161
161
|
else
|
162
162
|
if !foreign_key
|
163
|
-
|
164
|
-
.opts[:schema_mapper]
|
165
|
-
.dto(:db_load)
|
166
|
-
|
167
|
-
name = underscore(demodulize(dto_class.name))
|
168
|
-
|
169
|
-
root_ids = list.map(&:"#{"#{name}_id".to_sym}").uniq
|
170
|
-
foreign_key = :id
|
171
|
-
else
|
172
|
-
root_ids = list.map(&:"#{foreign_key}")
|
173
|
-
foreign_key = :id
|
163
|
+
foreign_key = :"#{assoc_name}_id"
|
174
164
|
end
|
165
|
+
|
166
|
+
root_ids = list.map(&:"#{foreign_key}").compact
|
175
167
|
end
|
176
168
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
items = add_scopes(default_scope, scope, global_opts[assoc_name])
|
169
|
+
scope ||= assoc_dao
|
170
|
+
scope = scope.where((reverse ? foreign_key : :id) => root_ids)
|
171
|
+
|
172
|
+
items = add_scopes(scope, global_opts[assoc_name])
|
182
173
|
end
|
183
174
|
|
184
|
-
assoc =
|
185
|
-
index_by(items) { _1.send(foreign_key) }
|
186
|
-
else
|
187
|
-
items
|
188
|
-
end
|
175
|
+
assoc = index_by(items) { _1.send(reverse ? foreign_key : :id) }
|
189
176
|
|
190
177
|
populate_association(
|
191
178
|
list,
|
@@ -224,11 +211,10 @@ module ReeDao
|
|
224
211
|
|
225
212
|
root_ids = list.map(&:"#{primary_key}")
|
226
213
|
|
227
|
-
|
228
|
-
|
229
|
-
end
|
214
|
+
scope ||= assoc_dao
|
215
|
+
scope = scope.where(foreign_key => root_ids)
|
230
216
|
|
231
|
-
items = add_scopes(
|
217
|
+
items = add_scopes(scope, global_opts[assoc_name])
|
232
218
|
end
|
233
219
|
|
234
220
|
assoc = if foreign_key
|
@@ -289,12 +275,12 @@ module ReeDao
|
|
289
275
|
end
|
290
276
|
end
|
291
277
|
|
292
|
-
contract(Nilor[Sequel::Dataset], Nilor[
|
293
|
-
def add_scopes(
|
294
|
-
res =
|
295
|
-
|
296
|
-
|
297
|
-
|
278
|
+
contract(Nilor[Sequel::Dataset], Nilor[Proc] => Array)
|
279
|
+
def add_scopes(scope, named_scope)
|
280
|
+
res = if named_scope
|
281
|
+
named_scope.call(scope)
|
282
|
+
else
|
283
|
+
scope
|
298
284
|
end
|
299
285
|
|
300
286
|
res.all
|
@@ -278,6 +278,7 @@ RSpec.describe :load_agg do
|
|
278
278
|
belongs_to :organization
|
279
279
|
|
280
280
|
has_many :books, -> { books_opts(title) }
|
281
|
+
has_many :active_books, books
|
281
282
|
end
|
282
283
|
end
|
283
284
|
|
@@ -508,6 +509,45 @@ RSpec.describe :load_agg do
|
|
508
509
|
expect(res[0].books[1].author).to eq(nil)
|
509
510
|
}
|
510
511
|
|
512
|
+
it {
|
513
|
+
organizations.delete_all
|
514
|
+
users.delete_all
|
515
|
+
user_passports.delete_all
|
516
|
+
books.delete_all
|
517
|
+
chapters.delete_all
|
518
|
+
|
519
|
+
organization = ReeDaoLoadAggTest::Organization.new(name: "Test Org")
|
520
|
+
organizations.put(organization)
|
521
|
+
|
522
|
+
user_1 = ReeDaoLoadAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
|
523
|
+
user_2 = ReeDaoLoadAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
|
524
|
+
users.put(user_1)
|
525
|
+
users.put(user_2)
|
526
|
+
|
527
|
+
book_1 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1984")
|
528
|
+
book_2 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1408")
|
529
|
+
|
530
|
+
books.put(book_1)
|
531
|
+
books.put(book_2)
|
532
|
+
|
533
|
+
res = users_agg.call(
|
534
|
+
users.all
|
535
|
+
)
|
536
|
+
|
537
|
+
expect(res[0].books).to_not eq([])
|
538
|
+
expect(res[1].books).to eq([])
|
539
|
+
|
540
|
+
books.delete(book_1)
|
541
|
+
books.delete(book_2)
|
542
|
+
|
543
|
+
res = users_agg.call(
|
544
|
+
users.all
|
545
|
+
)
|
546
|
+
|
547
|
+
expect(res[0].books).to eq([])
|
548
|
+
expect(res[1].books).to eq([])
|
549
|
+
}
|
550
|
+
|
511
551
|
it {
|
512
552
|
organizations.delete_all
|
513
553
|
users.delete_all
|
@@ -533,6 +573,7 @@ RSpec.describe :load_agg do
|
|
533
573
|
expect(res_user.id).to eq(user_1.id)
|
534
574
|
expect(res_user.organization).to eq(organization)
|
535
575
|
expect(res_user.books.count).to eq(1)
|
576
|
+
expect(res_user.active_books.count).to eq(2)
|
536
577
|
}
|
537
578
|
|
538
579
|
it {
|
@@ -105,6 +105,14 @@ class ReeDaoLoadAggTest::User
|
|
105
105
|
@books
|
106
106
|
end
|
107
107
|
|
108
|
+
def set_active_books(books)
|
109
|
+
@active_books = books
|
110
|
+
end
|
111
|
+
|
112
|
+
def active_books
|
113
|
+
@active_books
|
114
|
+
end
|
115
|
+
|
108
116
|
contract(ArrayOf[ReeDaoLoadAggTest::Book] => nil)
|
109
117
|
def set_books(books)
|
110
118
|
@books = books; nil
|
data/lib/ree_lib/version.rb
CHANGED