ree_lib 1.0.58 → 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 +24 -35
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/load_agg_spec.rb +84 -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
|
@@ -242,7 +228,8 @@ module ReeDao
|
|
242
228
|
assoc,
|
243
229
|
assoc_name,
|
244
230
|
setter: setter,
|
245
|
-
primary_key: primary_key
|
231
|
+
primary_key: primary_key,
|
232
|
+
multiple: true
|
246
233
|
)
|
247
234
|
|
248
235
|
assoc
|
@@ -255,10 +242,11 @@ module ReeDao
|
|
255
242
|
Kwargs[
|
256
243
|
primary_key: Nilor[Symbol],
|
257
244
|
reverse: Nilor[Bool],
|
258
|
-
setter: Nilor[Or[Symbol, Proc]]
|
245
|
+
setter: Nilor[Or[Symbol, Proc]],
|
246
|
+
multiple: Bool
|
259
247
|
] => Any
|
260
248
|
)
|
261
|
-
def populate_association(list, association_index, assoc_name, primary_key: nil, reverse: nil, setter: nil)
|
249
|
+
def populate_association(list, association_index, assoc_name, primary_key: nil, reverse: nil, setter: nil, multiple: false)
|
262
250
|
assoc_setter = if setter
|
263
251
|
setter
|
264
252
|
else
|
@@ -275,7 +263,8 @@ module ReeDao
|
|
275
263
|
reverse ? primary_key : "#{assoc_name}_id"
|
276
264
|
end
|
277
265
|
value = association_index[item.send(key)]
|
278
|
-
|
266
|
+
|
267
|
+
value = [] if value.nil? && multiple
|
279
268
|
|
280
269
|
begin
|
281
270
|
item.send(assoc_setter, value)
|
@@ -286,12 +275,12 @@ module ReeDao
|
|
286
275
|
end
|
287
276
|
end
|
288
277
|
|
289
|
-
contract(Nilor[Sequel::Dataset], Nilor[
|
290
|
-
def add_scopes(
|
291
|
-
res =
|
292
|
-
|
293
|
-
|
294
|
-
|
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
|
295
284
|
end
|
296
285
|
|
297
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
|
|
@@ -465,6 +466,88 @@ RSpec.describe :load_agg do
|
|
465
466
|
expect(res_user.custom_field).to_not eq(nil)
|
466
467
|
}
|
467
468
|
|
469
|
+
it {
|
470
|
+
organizations.delete_all
|
471
|
+
users.delete_all
|
472
|
+
user_passports.delete_all
|
473
|
+
books.delete_all
|
474
|
+
chapters.delete_all
|
475
|
+
|
476
|
+
organization = ReeDaoLoadAggTest::Organization.new(name: "Test Org")
|
477
|
+
organizations.put(organization)
|
478
|
+
|
479
|
+
user_1 = ReeDaoLoadAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
|
480
|
+
user_2 = ReeDaoLoadAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
|
481
|
+
users.put(user_1)
|
482
|
+
users.put(user_2)
|
483
|
+
|
484
|
+
book_1 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1984")
|
485
|
+
book_2 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1408")
|
486
|
+
|
487
|
+
books.put(book_1)
|
488
|
+
books.put(book_2)
|
489
|
+
|
490
|
+
author_1 = ReeDaoLoadAggTest::Author.new(book_id: book_1.id, name: "George Orwell")
|
491
|
+
author_2 = ReeDaoLoadAggTest::Author.new(book_id: book_2.id, name: "Stephen King")
|
492
|
+
authors.put(author_1)
|
493
|
+
authors.put(author_2)
|
494
|
+
|
495
|
+
res = users_agg.call(
|
496
|
+
users.all
|
497
|
+
)
|
498
|
+
|
499
|
+
expect(res[0].books.first.author).to_not eq(nil)
|
500
|
+
|
501
|
+
authors.delete(author_1)
|
502
|
+
authors.delete(author_2)
|
503
|
+
|
504
|
+
res = users_agg.call(
|
505
|
+
users.all
|
506
|
+
)
|
507
|
+
|
508
|
+
expect(res[0].books[0].author).to eq(nil)
|
509
|
+
expect(res[0].books[1].author).to eq(nil)
|
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
|
+
|
468
551
|
it {
|
469
552
|
organizations.delete_all
|
470
553
|
users.delete_all
|
@@ -490,6 +573,7 @@ RSpec.describe :load_agg do
|
|
490
573
|
expect(res_user.id).to eq(user_1.id)
|
491
574
|
expect(res_user.organization).to eq(organization)
|
492
575
|
expect(res_user.books.count).to eq(1)
|
576
|
+
expect(res_user.active_books.count).to eq(2)
|
493
577
|
}
|
494
578
|
|
495
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