orchid-orm 1.74.0 → 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.mjs CHANGED
@@ -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
  });
@@ -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
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,