@omnifyjp/ts 5.9.20 → 5.9.21
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.
|
@@ -723,7 +723,9 @@ function buildRelations(schemaName, properties, propertyOrder, modelNamespace, r
|
|
|
723
723
|
const pivotName = [schemaName, target].sort().join('');
|
|
724
724
|
const pivotSchema = reader.getSchema(pivotName);
|
|
725
725
|
if (pivotSchema?.properties) {
|
|
726
|
-
pivotProperties = Object.
|
|
726
|
+
pivotProperties = Object.entries(pivotSchema.properties).map(([propName, prop]) => prop.type === 'Association' && !prop.mappedBy
|
|
727
|
+
? prop.column || toFkColumnName(propName)
|
|
728
|
+
: toSnakeCase(propName));
|
|
727
729
|
}
|
|
728
730
|
}
|
|
729
731
|
const result = buildRelation(propName, prop, ns, { sourceTableName, targetTableName, pivotProperties });
|
|
@@ -126,6 +126,11 @@ function generateBasePolicyClass(name, schema, reader, config) {
|
|
|
126
126
|
methods.push(buildMethod('forceDelete', modelName, true, forceDeleteBody));
|
|
127
127
|
}
|
|
128
128
|
const cidrHelper = needsCidrHelper ? buildCidrHelper() : '';
|
|
129
|
+
const imports = [...new Set([
|
|
130
|
+
`use ${modelNamespace}\\${modelName};`,
|
|
131
|
+
'use App\\Models\\User;',
|
|
132
|
+
'use Illuminate\\Auth\\Access\\HandlesAuthorization;',
|
|
133
|
+
])].join('\n');
|
|
129
134
|
const content = `<?php
|
|
130
135
|
|
|
131
136
|
namespace ${baseNamespace};
|
|
@@ -137,9 +142,7 @@ namespace ${baseNamespace};
|
|
|
137
142
|
* @generated by omnify
|
|
138
143
|
*/
|
|
139
144
|
|
|
140
|
-
|
|
141
|
-
use App\\Models\\User;
|
|
142
|
-
use Illuminate\\Auth\\Access\\HandlesAuthorization;
|
|
145
|
+
${imports}
|
|
143
146
|
|
|
144
147
|
class ${modelName}PolicyBase
|
|
145
148
|
{
|
|
@@ -135,7 +135,9 @@ function belongsToMany(propName, property, target, ns, context) {
|
|
|
135
135
|
// v5.0.0; pivot columns now live on the pivot schema itself.
|
|
136
136
|
const pivotCols = context?.pivotProperties ?? [];
|
|
137
137
|
if (pivotCols.length > 0) {
|
|
138
|
-
|
|
138
|
+
// Callers pass physical column names. Association properties on an
|
|
139
|
+
// explicit pivot are resolved to `<name>_id` before reaching here.
|
|
140
|
+
const fields = pivotCols.map(k => `'${k}'`).join(', ');
|
|
139
141
|
chain += `\n ->withPivot(${fields})`;
|
|
140
142
|
}
|
|
141
143
|
chain += `\n ->withTimestamps()`;
|
package/dist/types.d.ts
CHANGED
|
@@ -338,6 +338,8 @@ export interface PropertyDefinition {
|
|
|
338
338
|
readonly morphName?: string;
|
|
339
339
|
readonly joinTable?: string;
|
|
340
340
|
readonly mappedBy?: string;
|
|
341
|
+
/** Physical FK column override for owning ManyToOne/OneToOne associations. */
|
|
342
|
+
readonly column?: string;
|
|
341
343
|
readonly orderBy?: readonly OrderByItem[];
|
|
342
344
|
readonly useCurrent?: boolean;
|
|
343
345
|
readonly deprecated?: boolean;
|