@omnifyjp/ts 6.7.15 → 6.7.16
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.
|
@@ -31,10 +31,11 @@ export declare function getReturnType(relation: string): string;
|
|
|
31
31
|
/**
|
|
32
32
|
* Resolve the child-table FK column for a OneToMany when `mappedBy` / `inversedBy`
|
|
33
33
|
* is absent. Prefer the single inverse ManyToOne on the target (omnify-go#166
|
|
34
|
-
* `column:` override included); if zero
|
|
35
|
-
*
|
|
34
|
+
* `column:` override included); if zero matches, fall back to the owning schema
|
|
35
|
+
* name (external targets). If two or more matches, throw — omnify-go#242.
|
|
36
|
+
* Issue #237.
|
|
36
37
|
*/
|
|
37
|
-
export declare function resolveHasManyForeignKey(
|
|
38
|
+
export declare function resolveHasManyForeignKey(propName: string, target: string, context?: RelationContext): string;
|
|
38
39
|
/**
|
|
39
40
|
* Build a chained `->orderBy('col', 'dir')` PHP fragment from an OrderByList.
|
|
40
41
|
* Returns an empty string if no ordering is configured. Issue #40.
|
|
@@ -116,10 +116,11 @@ function hasMany(propName, property, target, ns, context) {
|
|
|
116
116
|
/**
|
|
117
117
|
* Resolve the child-table FK column for a OneToMany when `mappedBy` / `inversedBy`
|
|
118
118
|
* is absent. Prefer the single inverse ManyToOne on the target (omnify-go#166
|
|
119
|
-
* `column:` override included); if zero
|
|
120
|
-
*
|
|
119
|
+
* `column:` override included); if zero matches, fall back to the owning schema
|
|
120
|
+
* name (external targets). If two or more matches, throw — omnify-go#242.
|
|
121
|
+
* Issue #237.
|
|
121
122
|
*/
|
|
122
|
-
export function resolveHasManyForeignKey(
|
|
123
|
+
export function resolveHasManyForeignKey(propName, target, context) {
|
|
123
124
|
const reader = context?.reader;
|
|
124
125
|
const owningSchemaName = context?.sourceSchemaName;
|
|
125
126
|
if (reader && owningSchemaName && target) {
|
|
@@ -127,9 +128,13 @@ export function resolveHasManyForeignKey(_propName, target, context) {
|
|
|
127
128
|
if (matches.length === 1) {
|
|
128
129
|
return matches[0];
|
|
129
130
|
}
|
|
131
|
+
if (matches.length >= 2) {
|
|
132
|
+
const columnList = matches.join(', ');
|
|
133
|
+
throw new Error(`${owningSchemaName}.${propName}: target ${target} has ${matches.length} ManyToOne associations back to ${owningSchemaName} (${columnList}) — set mappedBy: on the OneToMany to pick one`);
|
|
134
|
+
}
|
|
130
135
|
return toFkColumnName(owningSchemaName);
|
|
131
136
|
}
|
|
132
|
-
return toFkColumnName(
|
|
137
|
+
return toFkColumnName(propName);
|
|
133
138
|
}
|
|
134
139
|
function findInverseManyToOneFkColumns(reader, targetSchemaName, owningSchemaName) {
|
|
135
140
|
const targetSchema = reader.getSchema(targetSchemaName);
|