@famgia/omnify-laravel 0.0.112 → 0.0.113

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 CHANGED
@@ -31,7 +31,7 @@ import {
31
31
  shouldGenerateAIGuides,
32
32
  toColumnName,
33
33
  toTableName
34
- } from "./chunk-GDFAEEEG.js";
34
+ } from "./chunk-3YANFHE5.js";
35
35
  export {
36
36
  extractManyToManyRelations,
37
37
  extractMorphToManyRelations,
package/dist/plugin.cjs CHANGED
@@ -591,7 +591,29 @@ function extractManyToManyRelations(schema, allSchemas) {
591
591
  const targetSchema = allSchemas[targetName];
592
592
  const targetTable = toTableName(targetName);
593
593
  const targetPkType = targetSchema ? getIdType(targetSchema) : "BigInt";
594
- const isOwningSide = assocProp.owning ?? schema.name < targetName;
594
+ let isOwningSide;
595
+ if (assocProp.owning !== void 0) {
596
+ isOwningSide = assocProp.owning;
597
+ } else if (assocProp.pivotFields && Object.keys(assocProp.pivotFields).length > 0) {
598
+ isOwningSide = true;
599
+ } else {
600
+ let targetHasMappedByToThisSide = false;
601
+ if (targetSchema?.properties) {
602
+ for (const [, targetProp] of Object.entries(targetSchema.properties)) {
603
+ if (targetProp.type !== "Association") continue;
604
+ const targetAssoc = targetProp;
605
+ if (targetAssoc.relation === "ManyToMany" && targetAssoc.target === schema.name && targetAssoc.mappedBy) {
606
+ targetHasMappedByToThisSide = true;
607
+ break;
608
+ }
609
+ }
610
+ }
611
+ if (targetHasMappedByToThisSide) {
612
+ isOwningSide = true;
613
+ } else {
614
+ isOwningSide = schema.name < targetName;
615
+ }
616
+ }
595
617
  if (!isOwningSide) {
596
618
  continue;
597
619
  }