@famgia/omnify-laravel 0.0.112 → 0.0.114

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
@@ -619,7 +619,29 @@ function extractManyToManyRelations(schema, allSchemas) {
619
619
  const targetSchema = allSchemas[targetName];
620
620
  const targetTable = toTableName(targetName);
621
621
  const targetPkType = targetSchema ? getIdType(targetSchema) : "BigInt";
622
- const isOwningSide = assocProp.owning ?? schema.name < targetName;
622
+ let isOwningSide;
623
+ if (assocProp.owning !== void 0) {
624
+ isOwningSide = assocProp.owning;
625
+ } else if (assocProp.pivotFields && Object.keys(assocProp.pivotFields).length > 0) {
626
+ isOwningSide = true;
627
+ } else {
628
+ let targetHasMappedByToThisSide = false;
629
+ if (targetSchema?.properties) {
630
+ for (const [, targetProp] of Object.entries(targetSchema.properties)) {
631
+ if (targetProp.type !== "Association") continue;
632
+ const targetAssoc = targetProp;
633
+ if (targetAssoc.relation === "ManyToMany" && targetAssoc.target === schema.name && targetAssoc.mappedBy) {
634
+ targetHasMappedByToThisSide = true;
635
+ break;
636
+ }
637
+ }
638
+ }
639
+ if (targetHasMappedByToThisSide) {
640
+ isOwningSide = true;
641
+ } else {
642
+ isOwningSide = schema.name < targetName;
643
+ }
644
+ }
623
645
  if (!isOwningSide) {
624
646
  continue;
625
647
  }