@strapi/database 4.23.1-alpha.0 → 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.js
CHANGED
|
@@ -2971,6 +2971,7 @@ const processOrderBy = (orderBy, ctx) => {
|
|
|
2971
2971
|
}
|
|
2972
2972
|
throw new Error("Invalid orderBy syntax");
|
|
2973
2973
|
};
|
|
2974
|
+
const joinColPrefix = "__strapi";
|
|
2974
2975
|
const XtoOne = async (input, ctx) => {
|
|
2975
2976
|
const { attribute, attributeName, results, populateValue, targetMeta, isCount } = input;
|
|
2976
2977
|
const { db, qb } = ctx;
|
|
@@ -2999,6 +3000,8 @@ const XtoOne = async (input, ctx) => {
|
|
|
2999
3000
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3000
3001
|
const alias = qb2.getAlias();
|
|
3001
3002
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3003
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3004
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3002
3005
|
const referencedValues = ___default.default.uniq(
|
|
3003
3006
|
results.map((r) => r[referencedColumnName]).filter((value) => !___default.default.isNil(value))
|
|
3004
3007
|
);
|
|
@@ -3040,8 +3043,8 @@ const XtoOne = async (input, ctx) => {
|
|
|
3040
3043
|
rootTable: qb2.alias,
|
|
3041
3044
|
on: joinTable.on,
|
|
3042
3045
|
orderBy: joinTable.orderBy
|
|
3043
|
-
}).addSelect(
|
|
3044
|
-
const map = ___default.default.groupBy(
|
|
3046
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3047
|
+
const map = ___default.default.groupBy(joinColRenameAs)(rows);
|
|
3045
3048
|
results.forEach((result) => {
|
|
3046
3049
|
result[attributeName] = fromTargetRow(___default.default.first(map[result[referencedColumnName]]));
|
|
3047
3050
|
});
|
|
@@ -3075,6 +3078,8 @@ const oneToMany = async (input, ctx) => {
|
|
|
3075
3078
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3076
3079
|
const alias = qb2.getAlias();
|
|
3077
3080
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3081
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3082
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3078
3083
|
const referencedValues = ___default.default.uniq(
|
|
3079
3084
|
results.map((r) => r[referencedColumnName]).filter((value) => !___default.default.isNil(value))
|
|
3080
3085
|
);
|
|
@@ -3092,9 +3097,9 @@ const oneToMany = async (input, ctx) => {
|
|
|
3092
3097
|
rootColumn: joinTable.inverseJoinColumn.referencedColumn,
|
|
3093
3098
|
rootTable: qb2.alias,
|
|
3094
3099
|
on: joinTable.on
|
|
3095
|
-
}).select([
|
|
3100
|
+
}).select([joinColSelect, qb2.raw("count(*) AS count")]).where({ [joinColAlias]: referencedValues }).groupBy(joinColAlias).execute({ mapResults: false });
|
|
3096
3101
|
const map2 = rows2.reduce((map3, row) => {
|
|
3097
|
-
map3[row[
|
|
3102
|
+
map3[row[joinColRenameAs]] = { count: Number(row.count) };
|
|
3098
3103
|
return map3;
|
|
3099
3104
|
}, {});
|
|
3100
3105
|
results.forEach((result) => {
|
|
@@ -3116,8 +3121,8 @@ const oneToMany = async (input, ctx) => {
|
|
|
3116
3121
|
rootTable: qb2.alias,
|
|
3117
3122
|
on: joinTable.on,
|
|
3118
3123
|
orderBy: ___default.default.mapValues((v) => populateValue.ordering || v, joinTable.orderBy)
|
|
3119
|
-
}).addSelect(
|
|
3120
|
-
const map = ___default.default.groupBy(
|
|
3124
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3125
|
+
const map = ___default.default.groupBy(joinColRenameAs)(rows);
|
|
3121
3126
|
results.forEach((r) => {
|
|
3122
3127
|
r[attributeName] = fromTargetRow(map[r[referencedColumnName]] || []);
|
|
3123
3128
|
});
|
|
@@ -3132,6 +3137,8 @@ const manyToMany = async (input, ctx) => {
|
|
|
3132
3137
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3133
3138
|
const alias = populateQb.getAlias();
|
|
3134
3139
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3140
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3141
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3135
3142
|
const referencedValues = ___default.default.uniq(
|
|
3136
3143
|
results.map((r) => r[referencedColumnName]).filter((value) => !___default.default.isNil(value))
|
|
3137
3144
|
);
|
|
@@ -3173,8 +3180,8 @@ const manyToMany = async (input, ctx) => {
|
|
|
3173
3180
|
rootTable: populateQb.alias,
|
|
3174
3181
|
on: joinTable.on,
|
|
3175
3182
|
orderBy: ___default.default.mapValues((v) => populateValue.ordering || v, joinTable.orderBy)
|
|
3176
|
-
}).addSelect(
|
|
3177
|
-
const map = ___default.default.groupBy(
|
|
3183
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3184
|
+
const map = ___default.default.groupBy(joinColRenameAs)(rows);
|
|
3178
3185
|
results.forEach((result) => {
|
|
3179
3186
|
result[attributeName] = fromTargetRow(map[result[referencedColumnName]] || []);
|
|
3180
3187
|
});
|