@strapi/database 4.23.1 → 4.24.0
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.
- package/dist/index.js +15 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -8
- package/dist/index.mjs.map +1 -1
- package/dist/query/helpers/populate/apply.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -2937,6 +2937,7 @@ const processOrderBy = (orderBy, ctx) => {
|
|
|
2937
2937
|
}
|
|
2938
2938
|
throw new Error("Invalid orderBy syntax");
|
|
2939
2939
|
};
|
|
2940
|
+
const joinColPrefix = "__strapi";
|
|
2940
2941
|
const XtoOne = async (input, ctx) => {
|
|
2941
2942
|
const { attribute, attributeName, results, populateValue, targetMeta, isCount } = input;
|
|
2942
2943
|
const { db, qb } = ctx;
|
|
@@ -2965,6 +2966,8 @@ const XtoOne = async (input, ctx) => {
|
|
|
2965
2966
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
2966
2967
|
const alias = qb2.getAlias();
|
|
2967
2968
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
2969
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
2970
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
2968
2971
|
const referencedValues = _.uniq(
|
|
2969
2972
|
results.map((r) => r[referencedColumnName]).filter((value) => !_.isNil(value))
|
|
2970
2973
|
);
|
|
@@ -3006,8 +3009,8 @@ const XtoOne = async (input, ctx) => {
|
|
|
3006
3009
|
rootTable: qb2.alias,
|
|
3007
3010
|
on: joinTable.on,
|
|
3008
3011
|
orderBy: joinTable.orderBy
|
|
3009
|
-
}).addSelect(
|
|
3010
|
-
const map2 = _.groupBy(
|
|
3012
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3013
|
+
const map2 = _.groupBy(joinColRenameAs)(rows);
|
|
3011
3014
|
results.forEach((result) => {
|
|
3012
3015
|
result[attributeName] = fromTargetRow(_.first(map2[result[referencedColumnName]]));
|
|
3013
3016
|
});
|
|
@@ -3041,6 +3044,8 @@ const oneToMany = async (input, ctx) => {
|
|
|
3041
3044
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3042
3045
|
const alias = qb2.getAlias();
|
|
3043
3046
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3047
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3048
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3044
3049
|
const referencedValues = _.uniq(
|
|
3045
3050
|
results.map((r) => r[referencedColumnName]).filter((value) => !_.isNil(value))
|
|
3046
3051
|
);
|
|
@@ -3058,9 +3063,9 @@ const oneToMany = async (input, ctx) => {
|
|
|
3058
3063
|
rootColumn: joinTable.inverseJoinColumn.referencedColumn,
|
|
3059
3064
|
rootTable: qb2.alias,
|
|
3060
3065
|
on: joinTable.on
|
|
3061
|
-
}).select([
|
|
3066
|
+
}).select([joinColSelect, qb2.raw("count(*) AS count")]).where({ [joinColAlias]: referencedValues }).groupBy(joinColAlias).execute({ mapResults: false });
|
|
3062
3067
|
const map22 = rows2.reduce((map3, row) => {
|
|
3063
|
-
map3[row[
|
|
3068
|
+
map3[row[joinColRenameAs]] = { count: Number(row.count) };
|
|
3064
3069
|
return map3;
|
|
3065
3070
|
}, {});
|
|
3066
3071
|
results.forEach((result) => {
|
|
@@ -3082,8 +3087,8 @@ const oneToMany = async (input, ctx) => {
|
|
|
3082
3087
|
rootTable: qb2.alias,
|
|
3083
3088
|
on: joinTable.on,
|
|
3084
3089
|
orderBy: _.mapValues((v) => populateValue.ordering || v, joinTable.orderBy)
|
|
3085
|
-
}).addSelect(
|
|
3086
|
-
const map2 = _.groupBy(
|
|
3090
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3091
|
+
const map2 = _.groupBy(joinColRenameAs)(rows);
|
|
3087
3092
|
results.forEach((r) => {
|
|
3088
3093
|
r[attributeName] = fromTargetRow(map2[r[referencedColumnName]] || []);
|
|
3089
3094
|
});
|
|
@@ -3098,6 +3103,8 @@ const manyToMany = async (input, ctx) => {
|
|
|
3098
3103
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3099
3104
|
const alias = populateQb.getAlias();
|
|
3100
3105
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3106
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3107
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3101
3108
|
const referencedValues = _.uniq(
|
|
3102
3109
|
results.map((r) => r[referencedColumnName]).filter((value) => !_.isNil(value))
|
|
3103
3110
|
);
|
|
@@ -3139,8 +3146,8 @@ const manyToMany = async (input, ctx) => {
|
|
|
3139
3146
|
rootTable: populateQb.alias,
|
|
3140
3147
|
on: joinTable.on,
|
|
3141
3148
|
orderBy: _.mapValues((v) => populateValue.ordering || v, joinTable.orderBy)
|
|
3142
|
-
}).addSelect(
|
|
3143
|
-
const map2 = _.groupBy(
|
|
3149
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3150
|
+
const map2 = _.groupBy(joinColRenameAs)(rows);
|
|
3144
3151
|
results.forEach((result) => {
|
|
3145
3152
|
result[attributeName] = fromTargetRow(map2[result[referencedColumnName]] || []);
|
|
3146
3153
|
});
|