@omnifyjp/omnify 5.8.37 → 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnifyjp/omnify",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.40",
|
|
4
4
|
"description": "Schema-driven code generation for Laravel, TypeScript, and SQL",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"zod": "^3.24.0"
|
|
37
37
|
},
|
|
38
38
|
"optionalDependencies": {
|
|
39
|
-
"@omnifyjp/omnify-darwin-arm64": "5.8.
|
|
40
|
-
"@omnifyjp/omnify-darwin-x64": "5.8.
|
|
41
|
-
"@omnifyjp/omnify-linux-x64": "5.8.
|
|
42
|
-
"@omnifyjp/omnify-linux-arm64": "5.8.
|
|
43
|
-
"@omnifyjp/omnify-win32-x64": "5.8.
|
|
39
|
+
"@omnifyjp/omnify-darwin-arm64": "5.8.40",
|
|
40
|
+
"@omnifyjp/omnify-darwin-x64": "5.8.40",
|
|
41
|
+
"@omnifyjp/omnify-linux-x64": "5.8.40",
|
|
42
|
+
"@omnifyjp/omnify-linux-arm64": "5.8.40",
|
|
43
|
+
"@omnifyjp/omnify-win32-x64": "5.8.40"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -20,9 +20,34 @@ namespace ${ns};
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
use Illuminate\\Database\\Eloquent\\Model;
|
|
23
|
+
use Illuminate\\Database\\Eloquent\\Relations\\Relation;
|
|
23
24
|
|
|
24
25
|
class BaseModel extends Model
|
|
25
26
|
{
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the polymorphic alias from the morph map, walking up the class
|
|
29
|
+
* hierarchy so application subclasses of a generated model still resolve.
|
|
30
|
+
*
|
|
31
|
+
* Omnify registers the morph map against the generated model classes. A
|
|
32
|
+
* project that subclasses one and instantiates the subclass would otherwise
|
|
33
|
+
* throw ClassMorphViolationException under an enforced morph map, because the
|
|
34
|
+
* subclass itself is absent from the map. Returning the nearest mapped
|
|
35
|
+
* ancestor's alias keeps stored type values stable across both layers.
|
|
36
|
+
*/
|
|
37
|
+
public function getMorphClass(): string
|
|
38
|
+
{
|
|
39
|
+
$morphMap = Relation::morphMap();
|
|
40
|
+
|
|
41
|
+
for ($class = static::class; $class !== false; $class = get_parent_class($class)) {
|
|
42
|
+
$alias = array_search($class, $morphMap, true);
|
|
43
|
+
|
|
44
|
+
if ($alias !== false) {
|
|
45
|
+
return $alias;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return parent::getMorphClass();
|
|
50
|
+
}
|
|
26
51
|
}
|
|
27
52
|
`;
|
|
28
53
|
const path = resolveSharedBasePath(config, 'Models', 'BaseModel.php', config.models.basePath);
|
|
@@ -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
|