@zenstackhq/orm 3.0.0-beta.30 → 3.0.0-beta.32

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.cjs CHANGED
@@ -432,15 +432,16 @@ function getManyToManyRelation(schema, model, field) {
432
432
  if (!fieldDef.array || !fieldDef.relation?.opposite) {
433
433
  return void 0;
434
434
  }
435
+ const realModel = fieldDef.originModel ?? model;
435
436
  const oppositeFieldDef = requireField(schema, fieldDef.type, fieldDef.relation.opposite);
436
437
  if (oppositeFieldDef.array) {
437
438
  const sortedModelNames = [
438
- model,
439
+ realModel,
439
440
  fieldDef.type
440
441
  ].sort();
441
442
  let orderedFK;
442
- if (model !== fieldDef.type) {
443
- orderedFK = sortedModelNames[0] === model ? [
443
+ if (realModel !== fieldDef.type) {
444
+ orderedFK = sortedModelNames[0] === realModel ? [
444
445
  "A",
445
446
  "B"
446
447
  ] : [
@@ -460,7 +461,7 @@ function getManyToManyRelation(schema, model, field) {
460
461
  "A"
461
462
  ];
462
463
  }
463
- const modelIdFields = requireIdFields(schema, model);
464
+ const modelIdFields = requireIdFields(schema, realModel);
464
465
  (0, import_common_helpers.invariant)(modelIdFields.length === 1, "Only single-field ID is supported for many-to-many relation");
465
466
  const otherIdFields = requireIdFields(schema, fieldDef.type);
466
467
  (0, import_common_helpers.invariant)(otherIdFields.length === 1, "Only single-field ID is supported for many-to-many relation");
@@ -1546,7 +1547,13 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
1546
1547
  } else if (value instanceof AnyNullClass) {
1547
1548
  (0, import_common_helpers3.invariant)(false, "should not reach here: AnyNull is not a valid input value");
1548
1549
  }
1549
- if (Array.isArray(value)) {
1550
+ if (isTypeDef(this.schema, type)) {
1551
+ if (typeof value !== "string") {
1552
+ return JSON.stringify(value);
1553
+ } else {
1554
+ return value;
1555
+ }
1556
+ } else if (Array.isArray(value)) {
1550
1557
  if (type === "Json" && !forArrayField) {
1551
1558
  return JSON.stringify(value);
1552
1559
  } else {