orchid-orm 1.73.1 → 1.75.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.d.ts +75 -80
- package/dist/index.js +10 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -209,7 +209,7 @@ function joinHasThrough(q, baseQuery, joiningQuery, throughRelation, sourceRelat
|
|
|
209
209
|
function joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len) {
|
|
210
210
|
const baseAs = getQueryAs(baseQuery);
|
|
211
211
|
const q = joiningQuery.clone();
|
|
212
|
-
setQueryObjectValueImmutable(q, "joinedShapes", baseAs, baseQuery.q.
|
|
212
|
+
setQueryObjectValueImmutable(q, "joinedShapes", baseAs, baseQuery.q.selectShape);
|
|
213
213
|
for (let i = 0; i < len; i++) pushQueryOnForOuter(q, baseQuery, joiningQuery, foreignKeys[i], `${baseAs}.${primaryKeys[i]}`);
|
|
214
214
|
return q;
|
|
215
215
|
}
|
|
@@ -410,9 +410,10 @@ var BelongsToVirtualColumn = class extends VirtualColumn {
|
|
|
410
410
|
this.nestedUpdate(queryForUpdate, set, data);
|
|
411
411
|
}
|
|
412
412
|
};
|
|
413
|
-
const getBelongsToRequired = (tableConfig, relation) => {
|
|
413
|
+
const getBelongsToRequired = (tableConfig, relatedTableConfig, relation) => {
|
|
414
414
|
const { required } = relation.options;
|
|
415
415
|
if (typeof required === "boolean") return required;
|
|
416
|
+
if (relatedTableConfig.softDelete) return false;
|
|
416
417
|
return relation.options.columns.every((key) => {
|
|
417
418
|
return !tableConfig.columns.shape[key].data.isNullable;
|
|
418
419
|
});
|
|
@@ -437,7 +438,7 @@ const makeBelongsToMethod = (tableConfig, table, relation, relationName, query)
|
|
|
437
438
|
const join = (baseQuery, joiningQuery, primaryKeys, foreignKeys) => {
|
|
438
439
|
const baseAs = getQueryAs(baseQuery);
|
|
439
440
|
const q = joiningQuery.clone();
|
|
440
|
-
setQueryObjectValueImmutable(q, "joinedShapes", baseAs, baseQuery.q.
|
|
441
|
+
setQueryObjectValueImmutable(q, "joinedShapes", baseAs, baseQuery.q.selectShape);
|
|
441
442
|
for (let i = 0; i < len; i++) pushQueryOnForOuter(q, baseQuery, joiningQuery, primaryKeys[i], `${baseAs}.${foreignKeys[i]}`);
|
|
442
443
|
return q;
|
|
443
444
|
};
|
|
@@ -1129,7 +1130,7 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
|
|
|
1129
1130
|
const foreignAs = getQueryAs(joiningQuery);
|
|
1130
1131
|
return joinQuery(baseQuery, getQueryAs(baseQuery), foreignAs, {
|
|
1131
1132
|
...baseQuery.q.joinedShapes,
|
|
1132
|
-
[foreignAs]: joiningQuery.q.
|
|
1133
|
+
[foreignAs]: joiningQuery.q.selectShape
|
|
1133
1134
|
});
|
|
1134
1135
|
};
|
|
1135
1136
|
return {
|
|
@@ -1147,7 +1148,7 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
|
|
|
1147
1148
|
virtualColumn: new HasAndBelongsToManyVirtualColumn(subQuery, internalSchemaConfig, relationName, state),
|
|
1148
1149
|
joinQuery: joinQueryChainHOF(getPrimaryKeys(query), reverseJoin, (joiningQuery, baseQuery) => joinQuery(joiningQuery, getQueryAs(baseQuery), getQueryAs(joiningQuery), {
|
|
1149
1150
|
...joiningQuery.q.joinedShapes,
|
|
1150
|
-
[baseQuery.q.as || baseQuery.table]: baseQuery.q.
|
|
1151
|
+
[baseQuery.q.as || baseQuery.table]: baseQuery.q.selectShape
|
|
1151
1152
|
})),
|
|
1152
1153
|
reverseJoin,
|
|
1153
1154
|
modifyRelatedQuery(relationQuery) {
|
|
@@ -1359,6 +1360,7 @@ const applyRelations = (qb, tables, result, schema) => {
|
|
|
1359
1360
|
const data = {
|
|
1360
1361
|
relationName,
|
|
1361
1362
|
relation,
|
|
1363
|
+
otherTable: otherTable[1],
|
|
1362
1364
|
dbTable,
|
|
1363
1365
|
otherDbTable
|
|
1364
1366
|
};
|
|
@@ -1402,7 +1404,7 @@ const delayRelation = (delayedRelations, table, relationName, data) => {
|
|
|
1402
1404
|
if (tableRelations[relationName]) tableRelations[relationName].push(data);
|
|
1403
1405
|
else tableRelations[relationName] = [data];
|
|
1404
1406
|
};
|
|
1405
|
-
const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTable }, delayedRelations, schema) => {
|
|
1407
|
+
const applyRelation = (table, qb, { relationName, relation, otherTable, dbTable, otherDbTable }, delayedRelations, schema) => {
|
|
1406
1408
|
const baseQuery = Object.create(otherDbTable);
|
|
1407
1409
|
baseQuery.baseQuery = baseQuery;
|
|
1408
1410
|
const query = baseQuery.as(relationName);
|
|
@@ -1415,21 +1417,12 @@ const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTabl
|
|
|
1415
1417
|
else if (type === "hasAndBelongsToMany") data = makeHasAndBelongsToManyMethod(table, dbTable, qb, relation, relationName, query, schema);
|
|
1416
1418
|
else throw new Error(`Unknown relation type ${type}`);
|
|
1417
1419
|
if (data.returns === "one") {
|
|
1418
|
-
if (type === "belongsTo" ? getBelongsToRequired(table, relation) : relation.options.required) _queryTake(query);
|
|
1420
|
+
if (type === "belongsTo" ? getBelongsToRequired(table, otherTable, relation) : relation.options.required) _queryTake(query);
|
|
1419
1421
|
else _queryTakeOptional(query);
|
|
1420
1422
|
query.q.returnsOne = true;
|
|
1421
1423
|
}
|
|
1422
|
-
if (data.virtualColumn) dbTable.shape[relationName] = dbTable.q.
|
|
1424
|
+
if (data.virtualColumn) dbTable.shape[relationName] = dbTable.q.selectShape[relationName] = data.virtualColumn;
|
|
1423
1425
|
baseQuery.joinQuery = data.joinQuery;
|
|
1424
|
-
const { join: originalJoin } = baseQuery;
|
|
1425
|
-
baseQuery.join = function(...args) {
|
|
1426
|
-
if (args.length) return originalJoin.apply(this, args);
|
|
1427
|
-
else {
|
|
1428
|
-
const q = this.clone();
|
|
1429
|
-
q.q.innerJoinLateral = true;
|
|
1430
|
-
return q;
|
|
1431
|
-
}
|
|
1432
|
-
};
|
|
1433
1426
|
dbTable.relations[relationName] = {
|
|
1434
1427
|
table: otherDbTable,
|
|
1435
1428
|
query,
|