@omnifyjp/omnify 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/omnify",
3
- "version": "5.8.39",
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.39",
40
- "@omnifyjp/omnify-darwin-x64": "5.8.39",
41
- "@omnifyjp/omnify-linux-x64": "5.8.39",
42
- "@omnifyjp/omnify-linux-arm64": "5.8.39",
43
- "@omnifyjp/omnify-win32-x64": "5.8.39"
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
  }
@@ -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