@rebasepro/app 0.10.1-canary.ed8caed → 0.10.1-canary.g4db1bb1

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.es.js CHANGED
@@ -17565,21 +17565,29 @@ function isStorageProperty(property) {
17565
17565
  function getForeignKeyColumns(collection) {
17566
17566
  const keys = /* @__PURE__ */ new Set();
17567
17567
  const addRelationKeys = (relation) => {
17568
- if (relation.localKey) keys.add(relation.localKey);
17569
- if (relation.through?.sourceColumn) keys.add(relation.through.sourceColumn);
17570
- const firstStep = relation.joinPath?.[0];
17571
- if (firstStep) {
17572
- const from = firstStep.on?.from;
17573
- for (const column of Array.isArray(from) ? from : [from]) if (column) keys.add(column);
17568
+ switch (relation.kind) {
17569
+ case "belongsTo":
17570
+ keys.add(relation.localKey ?? generateForeignKeyName(relation.relationName ?? ""));
17571
+ break;
17572
+ case "manyToMany":
17573
+ if (relation.through?.sourceColumn) keys.add(relation.through.sourceColumn);
17574
+ break;
17575
+ case "via": {
17576
+ const from = relation.joinPath?.[0]?.on?.from;
17577
+ for (const column of Array.isArray(from) ? from : [from]) if (column) keys.add(column);
17578
+ break;
17579
+ }
17580
+ default: break;
17574
17581
  }
17575
17582
  };
17576
17583
  for (const relation of collection.relations ?? []) addRelationKeys(relation);
17577
17584
  for (const [key, propertyRaw] of Object.entries(collection.properties ?? {})) {
17578
17585
  const property = propertyRaw;
17579
17586
  if (!property || isPropertyBuilder(property) || property.type !== "relation") continue;
17580
- addRelationKeys(property);
17581
- if (property.relation) addRelationKeys(property.relation);
17582
- if ((property.cardinality ?? "one") === "one" && (property.direction ?? "owning") === "owning") keys.add(generateForeignKeyName(property.relationName || key));
17587
+ if (property.relation) addRelationKeys({
17588
+ ...property.relation,
17589
+ relationName: property.relation.relationName ?? key
17590
+ });
17583
17591
  }
17584
17592
  return keys;
17585
17593
  }
@@ -17600,7 +17608,7 @@ function scoreTitleCandidate(property, key, idKeys, foreignKeys) {
17600
17608
  if (isHidden$1(property)) return SCORE.DISQUALIFIED;
17601
17609
  if (isIdentifierProperty(property, key, idKeys, foreignKeys)) return SCORE.DISQUALIFIED;
17602
17610
  if (isStorageProperty(property)) return SCORE.DISQUALIFIED;
17603
- if (property.type === "relation") return property.cardinality === "many" || property.relation?.cardinality === "many" ? SCORE.DISQUALIFIED : SCORE.RELATION;
17611
+ if (property.type === "relation") return (property.resolvedRelation ? property.resolvedRelation.cardinality === "many" : property.relation?.kind === "hasMany" || property.relation?.kind === "manyToMany") ? SCORE.DISQUALIFIED : SCORE.RELATION;
17604
17612
  if (property.type === "reference") return SCORE.REFERENCE;
17605
17613
  if (property.type !== "string") return SCORE.DISQUALIFIED;
17606
17614
  if (property.userSelect) return SCORE.USER;