@omnifyjp/ts 5.8.39 → 5.8.40
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/php/model-generator.js +26 -1
- package/package.json +1 -1
|
@@ -116,6 +116,31 @@ function generateBaseModel(name, schema, reader, config) {
|
|
|
116
116
|
const fileAccessors = hasFiles ? buildFileAccessors(properties, propertyOrder, modelNamespace) : '';
|
|
117
117
|
const auditSection = buildAuditSection(options, reader, modelNamespace);
|
|
118
118
|
const nestedSetMethod = buildNestedSetParentIdMethod(nestedSetParentColumn);
|
|
119
|
+
// Authenticatable base models extend Illuminate's Authenticatable, not
|
|
120
|
+
// BaseModel, so they cannot inherit its getMorphClass() override. Give them
|
|
121
|
+
// their own copy so application subclasses (e.g.
|
|
122
|
+
// `App\Models\User extends App\Models\Omnify\User`) still resolve under an
|
|
123
|
+
// enforced morph map instead of throwing ClassMorphViolationException. #106
|
|
124
|
+
const morphClassMethod = isAuthenticatable ? `
|
|
125
|
+
/**
|
|
126
|
+
* Resolve the polymorphic alias from the morph map, walking up the class
|
|
127
|
+
* hierarchy so application subclasses of this generated model still resolve.
|
|
128
|
+
*/
|
|
129
|
+
public function getMorphClass(): string
|
|
130
|
+
{
|
|
131
|
+
$morphMap = \\Illuminate\\Database\\Eloquent\\Relations\\Relation::morphMap();
|
|
132
|
+
|
|
133
|
+
for ($class = static::class; $class !== false; $class = get_parent_class($class)) {
|
|
134
|
+
$alias = array_search($class, $morphMap, true);
|
|
135
|
+
|
|
136
|
+
if ($alias !== false) {
|
|
137
|
+
return $alias;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return parent::getMorphClass();
|
|
142
|
+
}
|
|
143
|
+
` : '';
|
|
119
144
|
let keyTypeSection = '';
|
|
120
145
|
if (idType === 'Uuid' || idType === 'Ulid' || idType === 'String') {
|
|
121
146
|
keyTypeSection = `
|
|
@@ -212,7 +237,7 @@ ${appends} ];
|
|
|
212
237
|
return [
|
|
213
238
|
${casts} ];
|
|
214
239
|
}
|
|
215
|
-
${auditLogProperties}${relations}${accessors}${fileAccessors}${auditSection}${nestedSetMethod}
|
|
240
|
+
${auditLogProperties}${relations}${accessors}${fileAccessors}${auditSection}${nestedSetMethod}${morphClassMethod}
|
|
216
241
|
}
|
|
217
242
|
`;
|
|
218
243
|
// Replace placeholder class name so the file matches resolved className
|