@omnifyjp/ts 5.8.37 → 5.8.39

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.
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/ts",
3
- "version": "5.8.37",
3
+ "version": "5.8.39",
4
4
  "description": "TypeScript model type generator from Omnify schemas.json",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",