@strapi/database 4.5.2 → 4.5.3
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.
|
@@ -446,6 +446,11 @@ const morphToMany = async (input, ctx) => {
|
|
|
446
446
|
.where({
|
|
447
447
|
[joinColumn.name]: referencedValues,
|
|
448
448
|
...(joinTable.on || {}),
|
|
449
|
+
// If the populateValue contains an "on" property,
|
|
450
|
+
// only populate the types defined in it
|
|
451
|
+
...('on' in populateValue
|
|
452
|
+
? { [morphColumn.typeColumn.name]: Object.keys(populateValue.on) }
|
|
453
|
+
: {}),
|
|
449
454
|
})
|
|
450
455
|
.orderBy([joinColumn.name, 'order'])
|
|
451
456
|
.execute({ mapResults: false });
|
|
@@ -470,6 +475,8 @@ const morphToMany = async (input, ctx) => {
|
|
|
470
475
|
}, {});
|
|
471
476
|
|
|
472
477
|
const map = {};
|
|
478
|
+
const { on, ...typePopulate } = populateValue;
|
|
479
|
+
|
|
473
480
|
for (const type of Object.keys(idsByType)) {
|
|
474
481
|
const ids = idsByType[type];
|
|
475
482
|
|
|
@@ -483,7 +490,7 @@ const morphToMany = async (input, ctx) => {
|
|
|
483
490
|
const qb = db.entityManager.createQueryBuilder(type);
|
|
484
491
|
|
|
485
492
|
const rows = await qb
|
|
486
|
-
.init(
|
|
493
|
+
.init(on?.[type] ?? typePopulate)
|
|
487
494
|
.addSelect(`${qb.alias}.${idColumn.referencedColumn}`)
|
|
488
495
|
.where({ [idColumn.referencedColumn]: ids })
|
|
489
496
|
.execute({ mapResults: false });
|
|
@@ -540,6 +547,8 @@ const morphToOne = async (input, ctx) => {
|
|
|
540
547
|
}, {});
|
|
541
548
|
|
|
542
549
|
const map = {};
|
|
550
|
+
const { on, ...typePopulate } = populateValue;
|
|
551
|
+
|
|
543
552
|
for (const type of Object.keys(idsByType)) {
|
|
544
553
|
const ids = idsByType[type];
|
|
545
554
|
|
|
@@ -552,7 +561,7 @@ const morphToOne = async (input, ctx) => {
|
|
|
552
561
|
const qb = db.entityManager.createQueryBuilder(type);
|
|
553
562
|
|
|
554
563
|
const rows = await qb
|
|
555
|
-
.init(
|
|
564
|
+
.init(on?.[type] ?? typePopulate)
|
|
556
565
|
.addSelect(`${qb.alias}.${idColumn.referencedColumn}`)
|
|
557
566
|
.where({ [idColumn.referencedColumn]: ids })
|
|
558
567
|
.execute({ mapResults: false });
|
|
@@ -579,7 +588,16 @@ const morphToOne = async (input, ctx) => {
|
|
|
579
588
|
|
|
580
589
|
// TODO: Omit limit & offset to avoid needing a query per result to avoid making too many queries
|
|
581
590
|
const pickPopulateParams = (populate) => {
|
|
582
|
-
const fieldsToPick = [
|
|
591
|
+
const fieldsToPick = [
|
|
592
|
+
'select',
|
|
593
|
+
'count',
|
|
594
|
+
'where',
|
|
595
|
+
'populate',
|
|
596
|
+
'orderBy',
|
|
597
|
+
'filters',
|
|
598
|
+
'ordering',
|
|
599
|
+
'on',
|
|
600
|
+
];
|
|
583
601
|
|
|
584
602
|
if (populate.count !== true) {
|
|
585
603
|
fieldsToPick.push('limit', 'offset');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/database",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.3",
|
|
4
4
|
"description": "Strapi's database layer",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"node": ">=14.19.1 <=18.x.x",
|
|
44
44
|
"npm": ">=6.0.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "5453885f7aa329f98d047a6030a8e98ba3cbdb41"
|
|
47
47
|
}
|