pinia-orm-edge 1.10.0-28586201.60fc813 → 1.10.0-28683029.86bd359

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/index.mjs CHANGED
@@ -3,10 +3,10 @@ import { defineStore, acceptHMRUpdate } from 'pinia';
3
3
  import { schema, normalize } from '@pinia-orm/normalizr';
4
4
  export { C as CastAttribute } from './shared/pinia-orm.4ff2e12f.mjs';
5
5
 
6
- var __defProp$k = Object.defineProperty;
7
- var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __publicField$k = (obj, key, value) => {
9
- __defNormalProp$k(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ var __defProp$l = Object.defineProperty;
7
+ var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField$l = (obj, key, value) => {
9
+ __defNormalProp$l(obj, typeof key !== "symbol" ? key + "" : key, value);
10
10
  return value;
11
11
  };
12
12
  class Attribute {
@@ -17,11 +17,11 @@ class Attribute {
17
17
  /**
18
18
  * The model instance.
19
19
  */
20
- __publicField$k(this, "model");
20
+ __publicField$l(this, "model");
21
21
  /**
22
22
  * The field name
23
23
  */
24
- __publicField$k(this, "key");
24
+ __publicField$l(this, "key");
25
25
  this.model = model;
26
26
  this.key = "";
27
27
  }
@@ -34,10 +34,10 @@ class Attribute {
34
34
  }
35
35
  }
36
36
 
37
- var __defProp$j = Object.defineProperty;
38
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
39
- var __publicField$j = (obj, key, value) => {
40
- __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
37
+ var __defProp$k = Object.defineProperty;
38
+ var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
39
+ var __publicField$k = (obj, key, value) => {
40
+ __defNormalProp$k(obj, typeof key !== "symbol" ? key + "" : key, value);
41
41
  return value;
42
42
  };
43
43
  class Relation extends Attribute {
@@ -49,15 +49,15 @@ class Relation extends Attribute {
49
49
  /**
50
50
  * The parent model.
51
51
  */
52
- __publicField$j(this, "parent");
52
+ __publicField$k(this, "parent");
53
53
  /**
54
54
  * The related model.
55
55
  */
56
- __publicField$j(this, "related");
56
+ __publicField$k(this, "related");
57
57
  /**
58
58
  * The delete mode
59
59
  */
60
- __publicField$j(this, "onDeleteMode");
60
+ __publicField$k(this, "onDeleteMode");
61
61
  this.parent = parent;
62
62
  this.related = related;
63
63
  }
@@ -119,10 +119,10 @@ class Relation extends Attribute {
119
119
  }
120
120
  }
121
121
 
122
- var __defProp$i = Object.defineProperty;
123
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
124
- var __publicField$i = (obj, key, value) => {
125
- __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
122
+ var __defProp$j = Object.defineProperty;
123
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
124
+ var __publicField$j = (obj, key, value) => {
125
+ __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
126
126
  return value;
127
127
  };
128
128
  class MorphTo extends Relation {
@@ -134,23 +134,23 @@ class MorphTo extends Relation {
134
134
  /**
135
135
  * The related models.
136
136
  */
137
- __publicField$i(this, "relatedModels");
137
+ __publicField$j(this, "relatedModels");
138
138
  /**
139
139
  * The related model dictionary.
140
140
  */
141
- __publicField$i(this, "relatedTypes");
141
+ __publicField$j(this, "relatedTypes");
142
142
  /**
143
143
  * The field name that contains id of the parent model.
144
144
  */
145
- __publicField$i(this, "morphId");
145
+ __publicField$j(this, "morphId");
146
146
  /**
147
147
  * The field name that contains type of the parent model.
148
148
  */
149
- __publicField$i(this, "morphType");
149
+ __publicField$j(this, "morphType");
150
150
  /**
151
151
  * The associated key of the child model.
152
152
  */
153
- __publicField$i(this, "ownerKey");
153
+ __publicField$j(this, "ownerKey");
154
154
  this.relatedModels = relatedModels;
155
155
  this.relatedTypes = this.createRelatedTypes(relatedModels);
156
156
  this.morphId = morphId;
@@ -265,27 +265,33 @@ class MorphTo extends Relation {
265
265
  }
266
266
  }
267
267
 
268
- var __defProp$h = Object.defineProperty;
269
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
270
- var __publicField$h = (obj, key, value) => {
271
- __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
268
+ var __defProp$i = Object.defineProperty;
269
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
270
+ var __publicField$i = (obj, key, value) => {
271
+ __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
272
272
  return value;
273
273
  };
274
274
  class Type extends Attribute {
275
275
  /**
276
276
  * Create a new Type attribute instance.
277
277
  */
278
- constructor(model, value = null) {
278
+ constructor(model, defaultValue = null) {
279
279
  super(model);
280
280
  /**
281
- * The default value for the attribute.
281
+ * The raw default value for the attribute (can be a function).
282
282
  */
283
- __publicField$h(this, "value");
283
+ __publicField$i(this, "rawDefaultValue");
284
284
  /**
285
285
  * Whether the attribute accepts `null` value or not.
286
286
  */
287
- __publicField$h(this, "isNullable", true);
288
- this.value = typeof value === "function" ? value() : value;
287
+ __publicField$i(this, "isNullable", true);
288
+ this.rawDefaultValue = defaultValue;
289
+ }
290
+ /**
291
+ * The computed default value of the attribute.
292
+ */
293
+ get defaultValue() {
294
+ return typeof this.rawDefaultValue === "function" ? this.rawDefaultValue() : this.rawDefaultValue;
289
295
  }
290
296
  /**
291
297
  * Set the nullable option to false.
@@ -296,7 +302,7 @@ class Type extends Attribute {
296
302
  }
297
303
  makeReturn(type, value) {
298
304
  if (value === void 0) {
299
- return this.value;
305
+ return this.defaultValue;
300
306
  }
301
307
  if (value === null) {
302
308
  if (!this.isNullable) {
@@ -317,24 +323,24 @@ class Type extends Attribute {
317
323
  }
318
324
  }
319
325
 
320
- var __defProp$g = Object.defineProperty;
321
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
322
- var __publicField$g = (obj, key, value) => {
323
- __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
326
+ var __defProp$h = Object.defineProperty;
327
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
328
+ var __publicField$h = (obj, key, value) => {
329
+ __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
324
330
  return value;
325
331
  };
326
332
  class Uid extends Type {
327
333
  constructor(model, options = {}) {
328
334
  super(model);
329
- __publicField$g(this, "options");
335
+ __publicField$h(this, "options");
330
336
  // This alphabet uses `A-Za-z0-9_-` symbols.
331
337
  // The order of characters is optimized for better gzip and brotli compression.
332
338
  // References to the same file (works both for gzip and brotli):
333
339
  // `'use`, `andom`, and `rict'`
334
340
  // References to the brotli default dictionary:
335
341
  // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
336
- __publicField$g(this, "alphabet", "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict");
337
- __publicField$g(this, "size", 21);
342
+ __publicField$h(this, "alphabet", "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict");
343
+ __publicField$h(this, "size", 21);
338
344
  this.options = typeof options === "number" ? { size: options } : options;
339
345
  this.alphabet = this.options.alphabet ?? this.alphabet;
340
346
  this.size = this.options.size ?? this.size;
@@ -351,10 +357,10 @@ class Uid extends Type {
351
357
  }
352
358
  }
353
359
 
354
- var __defProp$f = Object.defineProperty;
355
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
356
- var __publicField$f = (obj, key, value) => {
357
- __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
360
+ var __defProp$g = Object.defineProperty;
361
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
362
+ var __publicField$g = (obj, key, value) => {
363
+ __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
358
364
  return value;
359
365
  };
360
366
  class Schema {
@@ -365,11 +371,11 @@ class Schema {
365
371
  /**
366
372
  * The list of generated schemas.
367
373
  */
368
- __publicField$f(this, "schemas", {});
374
+ __publicField$g(this, "schemas", {});
369
375
  /**
370
376
  * The model instance.
371
377
  */
372
- __publicField$f(this, "model");
378
+ __publicField$g(this, "model");
373
379
  this.model = model;
374
380
  }
375
381
  /**
@@ -484,10 +490,10 @@ class Schema {
484
490
  }
485
491
  }
486
492
 
487
- var __defProp$e = Object.defineProperty;
488
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
489
- var __publicField$e = (obj, key, value) => {
490
- __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
493
+ var __defProp$f = Object.defineProperty;
494
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
495
+ var __publicField$f = (obj, key, value) => {
496
+ __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
491
497
  return value;
492
498
  };
493
499
  class Interpreter {
@@ -498,7 +504,7 @@ class Interpreter {
498
504
  /**
499
505
  * The model object.
500
506
  */
501
- __publicField$e(this, "model");
507
+ __publicField$f(this, "model");
502
508
  this.model = model;
503
509
  }
504
510
  process(data) {
@@ -586,10 +592,10 @@ function useDataStore(id, options, query) {
586
592
  });
587
593
  }
588
594
 
589
- var __defProp$d = Object.defineProperty;
590
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
591
- var __publicField$d = (obj, key, value) => {
592
- __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
595
+ var __defProp$e = Object.defineProperty;
596
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
597
+ var __publicField$e = (obj, key, value) => {
598
+ __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
593
599
  return value;
594
600
  };
595
601
  class BelongsToMany extends Relation {
@@ -601,27 +607,27 @@ class BelongsToMany extends Relation {
601
607
  /**
602
608
  * The pivot model.
603
609
  */
604
- __publicField$d(this, "pivot");
610
+ __publicField$e(this, "pivot");
605
611
  /**
606
612
  * The foreign key of the parent model.
607
613
  */
608
- __publicField$d(this, "foreignPivotKey");
614
+ __publicField$e(this, "foreignPivotKey");
609
615
  /**
610
616
  * The associated key of the relation.
611
617
  */
612
- __publicField$d(this, "relatedPivotKey");
618
+ __publicField$e(this, "relatedPivotKey");
613
619
  /**
614
620
  * The key name of the parent model.
615
621
  */
616
- __publicField$d(this, "parentKey");
622
+ __publicField$e(this, "parentKey");
617
623
  /**
618
624
  * The key name of the related model.
619
625
  */
620
- __publicField$d(this, "relatedKey");
626
+ __publicField$e(this, "relatedKey");
621
627
  /**
622
628
  * The key name of the pivot data.
623
629
  */
624
- __publicField$d(this, "pivotKey", "pivot");
630
+ __publicField$e(this, "pivotKey", "pivot");
625
631
  this.pivot = pivot;
626
632
  this.foreignPivotKey = foreignPivotKey;
627
633
  this.relatedPivotKey = relatedPivotKey;
@@ -647,7 +653,7 @@ class BelongsToMany extends Relation {
647
653
  const pivot = child.pivot ?? {};
648
654
  pivot[this.foreignPivotKey] = record[this.parentKey];
649
655
  pivot[this.relatedPivotKey] = child[this.relatedKey];
650
- child[`pivot_${this.pivot.$entity()}`] = pivot;
656
+ child[`pivot_${this.relatedPivotKey}_${this.pivot.$entity()}`] = pivot;
651
657
  }
652
658
  /**
653
659
  * Convert given value to the appropriate value for the attribute.
@@ -660,7 +666,7 @@ class BelongsToMany extends Relation {
660
666
  */
661
667
  match(relation, models, query) {
662
668
  const relatedModels = query.get(false);
663
- const pivotModels = query.newQuery(this.pivot.$entity()).whereIn(this.relatedPivotKey, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.foreignPivotKey, this.getKeys(models, this.parentKey)).groupBy(this.foreignPivotKey, this.relatedPivotKey).get();
669
+ const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedPivotKey, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.foreignPivotKey, this.getKeys(models, this.parentKey)).groupBy(this.foreignPivotKey, this.relatedPivotKey).get();
664
670
  models.forEach((parentModel) => {
665
671
  const relationResults = [];
666
672
  relatedModels.forEach((relatedModel) => {
@@ -668,7 +674,7 @@ class BelongsToMany extends Relation {
668
674
  if (!pivot) {
669
675
  return;
670
676
  }
671
- const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson());
677
+ const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson(), { operation: void 0 });
672
678
  relatedModelCopy.$setRelation("pivot", pivot);
673
679
  relationResults.push(relatedModelCopy);
674
680
  });
@@ -682,10 +688,10 @@ class BelongsToMany extends Relation {
682
688
  }
683
689
  }
684
690
 
685
- var __defProp$c = Object.defineProperty;
686
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
687
- var __publicField$c = (obj, key, value) => {
688
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
691
+ var __defProp$d = Object.defineProperty;
692
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
693
+ var __publicField$d = (obj, key, value) => {
694
+ __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
689
695
  return value;
690
696
  };
691
697
  class Query {
@@ -696,58 +702,58 @@ class Query {
696
702
  /**
697
703
  * The database instance.
698
704
  */
699
- __publicField$c(this, "database");
705
+ __publicField$d(this, "database");
700
706
  /**
701
707
  * The model object.
702
708
  */
703
- __publicField$c(this, "model");
709
+ __publicField$d(this, "model");
704
710
  /**
705
711
  * The where constraints for the query.
706
712
  */
707
- __publicField$c(this, "wheres", []);
713
+ __publicField$d(this, "wheres", []);
708
714
  /**
709
715
  * The orderings for the query.
710
716
  */
711
- __publicField$c(this, "orders", []);
717
+ __publicField$d(this, "orders", []);
712
718
  /**
713
719
  * The orderings for the query.
714
720
  */
715
- __publicField$c(this, "groups", []);
721
+ __publicField$d(this, "groups", []);
716
722
  /**
717
723
  * The maximum number of records to return.
718
724
  */
719
- __publicField$c(this, "take", null);
725
+ __publicField$d(this, "take", null);
720
726
  /**
721
727
  * The number of records to skip.
722
728
  */
723
- __publicField$c(this, "skip", 0);
729
+ __publicField$d(this, "skip", 0);
724
730
  /**
725
731
  * Fields that should be visible.
726
732
  */
727
- __publicField$c(this, "visible", ["*"]);
733
+ __publicField$d(this, "visible", ["*"]);
728
734
  /**
729
735
  * Fields that should be hidden.
730
736
  */
731
- __publicField$c(this, "hidden", []);
737
+ __publicField$d(this, "hidden", []);
732
738
  /**
733
739
  * The cache object.
734
740
  */
735
- __publicField$c(this, "cache");
741
+ __publicField$d(this, "cache");
736
742
  /**
737
743
  * The relationships that should be eager loaded.
738
744
  */
739
- __publicField$c(this, "eagerLoad", {});
745
+ __publicField$d(this, "eagerLoad", {});
740
746
  /**
741
747
  * The pinia store.
742
748
  */
743
- __publicField$c(this, "pinia");
744
- __publicField$c(this, "fromCache", false);
745
- __publicField$c(this, "cacheConfig", {});
746
- __publicField$c(this, "getNewHydrated", false);
749
+ __publicField$d(this, "pinia");
750
+ __publicField$d(this, "fromCache", false);
751
+ __publicField$d(this, "cacheConfig", {});
752
+ __publicField$d(this, "getNewHydrated", false);
747
753
  /**
748
754
  * Hydrated models. They are stored to prevent rerendering of child components.
749
755
  */
750
- __publicField$c(this, "hydratedDataCache");
756
+ __publicField$d(this, "hydratedDataCache");
751
757
  this.database = database;
752
758
  this.model = model;
753
759
  this.pinia = pinia;
@@ -1312,7 +1318,7 @@ class Query {
1312
1318
  const recordsByTypes = {};
1313
1319
  records = isArray(records) ? records : [records];
1314
1320
  records.forEach((record) => {
1315
- const recordType = modelTypesKeys.includes(`${record[this.model.$typeKey()]}`) || isChildEntity ? record[this.model.$typeKey()] ?? this.model.$fields()[this.model.$typeKey()].value : modelTypesKeys[0];
1321
+ const recordType = modelTypesKeys.includes(`${record[this.model.$typeKey()]}`) || isChildEntity ? record[this.model.$typeKey()] ?? this.model.$fields()[this.model.$typeKey()].defaultValue : modelTypesKeys[0];
1316
1322
  if (!recordsByTypes[recordType]) {
1317
1323
  recordsByTypes[recordType] = [];
1318
1324
  }
@@ -1352,7 +1358,7 @@ class Query {
1352
1358
  continue;
1353
1359
  }
1354
1360
  if (model.$isDirty()) {
1355
- model = this.hydrate(model.$getAttributes(), { operation: "set", action: existing ? "update" : "save" });
1361
+ model = this.hydrate(model.$getAttributes(), { operation: "set", action: "update" });
1356
1362
  }
1357
1363
  afterSavingHooks.push(() => model.$self().saved(model, record));
1358
1364
  afterSavingHooks.push(() => existing ? model.$self().updated(model, record) : model.$self().created(model, record));
@@ -1542,10 +1548,10 @@ class Query {
1542
1548
  }
1543
1549
  }
1544
1550
 
1545
- var __defProp$b = Object.defineProperty;
1546
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1547
- var __publicField$b = (obj, key, value) => {
1548
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
1551
+ var __defProp$c = Object.defineProperty;
1552
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1553
+ var __publicField$c = (obj, key, value) => {
1554
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
1549
1555
  return value;
1550
1556
  };
1551
1557
  var __accessCheck = (obj, member, msg) => {
@@ -1565,7 +1571,7 @@ var _a, _map;
1565
1571
  class WeakCache {
1566
1572
  constructor() {
1567
1573
  // @ts-expect-error dont know
1568
- __publicField$b(this, _a);
1574
+ __publicField$c(this, _a);
1569
1575
  __privateAdd(this, _map, /* @__PURE__ */ new Map());
1570
1576
  }
1571
1577
  has(key) {
@@ -1648,10 +1654,10 @@ const CONFIG_DEFAULTS = {
1648
1654
  };
1649
1655
  const config = { ...CONFIG_DEFAULTS };
1650
1656
 
1651
- var __defProp$a = Object.defineProperty;
1652
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1653
- var __publicField$a = (obj, key, value) => {
1654
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1657
+ var __defProp$b = Object.defineProperty;
1658
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1659
+ var __publicField$b = (obj, key, value) => {
1660
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
1655
1661
  return value;
1656
1662
  };
1657
1663
  class Repository {
@@ -1662,31 +1668,31 @@ class Repository {
1662
1668
  /**
1663
1669
  * The database instance.
1664
1670
  */
1665
- __publicField$a(this, "database");
1671
+ __publicField$b(this, "database");
1666
1672
  /**
1667
1673
  * The model instance.
1668
1674
  */
1669
- __publicField$a(this, "model");
1675
+ __publicField$b(this, "model");
1670
1676
  /**
1671
1677
  * The pinia instance
1672
1678
  */
1673
- __publicField$a(this, "pinia");
1679
+ __publicField$b(this, "pinia");
1674
1680
  /**
1675
1681
  * The cache instance
1676
1682
  */
1677
- __publicField$a(this, "queryCache");
1683
+ __publicField$b(this, "queryCache");
1678
1684
  /**
1679
1685
  * Hydrated models. They are stored to prevent rerendering of child components.
1680
1686
  */
1681
- __publicField$a(this, "hydratedDataCache");
1687
+ __publicField$b(this, "hydratedDataCache");
1682
1688
  /**
1683
1689
  * The model object to be used for the custom repository.
1684
1690
  */
1685
- __publicField$a(this, "use");
1691
+ __publicField$b(this, "use");
1686
1692
  /**
1687
1693
  * Global config
1688
1694
  */
1689
- __publicField$a(this, "config");
1695
+ __publicField$b(this, "config");
1690
1696
  this.config = config;
1691
1697
  this.database = database;
1692
1698
  this.pinia = pinia;
@@ -1957,16 +1963,16 @@ class Repository {
1957
1963
  * used when retrieving repository instance from `store.$repo()` method to
1958
1964
  * determine whether the passed in class is either a repository or a model.
1959
1965
  */
1960
- __publicField$a(Repository, "_isRepository", true);
1966
+ __publicField$b(Repository, "_isRepository", true);
1961
1967
  /**
1962
1968
  * The model object to be used for the custom repository.
1963
1969
  */
1964
- __publicField$a(Repository, "useModel");
1970
+ __publicField$b(Repository, "useModel");
1965
1971
 
1966
- var __defProp$9 = Object.defineProperty;
1967
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1968
- var __publicField$9 = (obj, key, value) => {
1969
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1972
+ var __defProp$a = Object.defineProperty;
1973
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1974
+ var __publicField$a = (obj, key, value) => {
1975
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1970
1976
  return value;
1971
1977
  };
1972
1978
  class Database {
@@ -1974,7 +1980,7 @@ class Database {
1974
1980
  /**
1975
1981
  * The list of registered models.
1976
1982
  */
1977
- __publicField$9(this, "models", {});
1983
+ __publicField$a(this, "models", {});
1978
1984
  }
1979
1985
  /**
1980
1986
  * Register the given model.
@@ -2065,7 +2071,7 @@ class Attr extends Type {
2065
2071
  * Make the value for the attribute.
2066
2072
  */
2067
2073
  make(value) {
2068
- return value === void 0 ? this.value : value;
2074
+ return value === void 0 ? this.defaultValue : value;
2069
2075
  }
2070
2076
  }
2071
2077
 
@@ -2114,10 +2120,10 @@ class Boolean extends Type {
2114
2120
  }
2115
2121
  }
2116
2122
 
2117
- var __defProp$8 = Object.defineProperty;
2118
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2119
- var __publicField$8 = (obj, key, value) => {
2120
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
2123
+ var __defProp$9 = Object.defineProperty;
2124
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2125
+ var __publicField$9 = (obj, key, value) => {
2126
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
2121
2127
  return value;
2122
2128
  };
2123
2129
  class HasOne extends Relation {
@@ -2129,11 +2135,11 @@ class HasOne extends Relation {
2129
2135
  /**
2130
2136
  * The foreign key of the parent model.
2131
2137
  */
2132
- __publicField$8(this, "foreignKey");
2138
+ __publicField$9(this, "foreignKey");
2133
2139
  /**
2134
2140
  * The local key of the parent model.
2135
2141
  */
2136
- __publicField$8(this, "localKey");
2142
+ __publicField$9(this, "localKey");
2137
2143
  this.foreignKey = foreignKey;
2138
2144
  this.localKey = localKey;
2139
2145
  }
@@ -2197,10 +2203,10 @@ class HasOne extends Relation {
2197
2203
  }
2198
2204
  }
2199
2205
 
2200
- var __defProp$7 = Object.defineProperty;
2201
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2202
- var __publicField$7 = (obj, key, value) => {
2203
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
2206
+ var __defProp$8 = Object.defineProperty;
2207
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2208
+ var __publicField$8 = (obj, key, value) => {
2209
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
2204
2210
  return value;
2205
2211
  };
2206
2212
  class BelongsTo extends Relation {
@@ -2212,15 +2218,15 @@ class BelongsTo extends Relation {
2212
2218
  /**
2213
2219
  * The child model instance of the relation.
2214
2220
  */
2215
- __publicField$7(this, "child");
2221
+ __publicField$8(this, "child");
2216
2222
  /**
2217
2223
  * The foreign key of the parent model.
2218
2224
  */
2219
- __publicField$7(this, "foreignKey");
2225
+ __publicField$8(this, "foreignKey");
2220
2226
  /**
2221
2227
  * The associated key on the parent model.
2222
2228
  */
2223
- __publicField$7(this, "ownerKey");
2229
+ __publicField$8(this, "ownerKey");
2224
2230
  this.foreignKey = foreignKey;
2225
2231
  this.ownerKey = ownerKey;
2226
2232
  this.child = child;
@@ -2297,10 +2303,10 @@ class BelongsTo extends Relation {
2297
2303
  }
2298
2304
  }
2299
2305
 
2300
- var __defProp$6 = Object.defineProperty;
2301
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2302
- var __publicField$6 = (obj, key, value) => {
2303
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
2306
+ var __defProp$7 = Object.defineProperty;
2307
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2308
+ var __publicField$7 = (obj, key, value) => {
2309
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
2304
2310
  return value;
2305
2311
  };
2306
2312
  class HasMany extends Relation {
@@ -2312,11 +2318,11 @@ class HasMany extends Relation {
2312
2318
  /**
2313
2319
  * The foreign key of the parent model.
2314
2320
  */
2315
- __publicField$6(this, "foreignKey");
2321
+ __publicField$7(this, "foreignKey");
2316
2322
  /**
2317
2323
  * The local key of the parent model.
2318
2324
  */
2319
- __publicField$6(this, "localKey");
2325
+ __publicField$7(this, "localKey");
2320
2326
  this.foreignKey = foreignKey;
2321
2327
  this.localKey = localKey;
2322
2328
  }
@@ -2385,10 +2391,10 @@ class HasMany extends Relation {
2385
2391
  }
2386
2392
  }
2387
2393
 
2388
- var __defProp$5 = Object.defineProperty;
2389
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2390
- var __publicField$5 = (obj, key, value) => {
2391
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
2394
+ var __defProp$6 = Object.defineProperty;
2395
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2396
+ var __publicField$6 = (obj, key, value) => {
2397
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
2392
2398
  return value;
2393
2399
  };
2394
2400
  class HasManyBy extends Relation {
@@ -2400,15 +2406,15 @@ class HasManyBy extends Relation {
2400
2406
  /**
2401
2407
  * The child model instance of the relation.
2402
2408
  */
2403
- __publicField$5(this, "child");
2409
+ __publicField$6(this, "child");
2404
2410
  /**
2405
2411
  * The foreign key of the parent model.
2406
2412
  */
2407
- __publicField$5(this, "foreignKey");
2413
+ __publicField$6(this, "foreignKey");
2408
2414
  /**
2409
2415
  * The owner key of the parent model.
2410
2416
  */
2411
- __publicField$5(this, "ownerKey");
2417
+ __publicField$6(this, "ownerKey");
2412
2418
  this.foreignKey = foreignKey;
2413
2419
  this.ownerKey = ownerKey;
2414
2420
  this.child = child;
@@ -2500,10 +2506,10 @@ class HasManyBy extends Relation {
2500
2506
  }
2501
2507
  }
2502
2508
 
2503
- var __defProp$4 = Object.defineProperty;
2504
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2505
- var __publicField$4 = (obj, key, value) => {
2506
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
2509
+ var __defProp$5 = Object.defineProperty;
2510
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2511
+ var __publicField$5 = (obj, key, value) => {
2512
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
2507
2513
  return value;
2508
2514
  };
2509
2515
  class MorphOne extends Relation {
@@ -2515,15 +2521,15 @@ class MorphOne extends Relation {
2515
2521
  /**
2516
2522
  * The field name that contains id of the parent model.
2517
2523
  */
2518
- __publicField$4(this, "morphId");
2524
+ __publicField$5(this, "morphId");
2519
2525
  /**
2520
2526
  * The field name that contains type of the parent model.
2521
2527
  */
2522
- __publicField$4(this, "morphType");
2528
+ __publicField$5(this, "morphType");
2523
2529
  /**
2524
2530
  * The local key of the model.
2525
2531
  */
2526
- __publicField$4(this, "localKey");
2532
+ __publicField$5(this, "localKey");
2527
2533
  this.morphId = morphId;
2528
2534
  this.morphType = morphType;
2529
2535
  this.localKey = localKey;
@@ -2580,10 +2586,10 @@ class MorphOne extends Relation {
2580
2586
  }
2581
2587
  }
2582
2588
 
2583
- var __defProp$3 = Object.defineProperty;
2584
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2585
- var __publicField$3 = (obj, key, value) => {
2586
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
2589
+ var __defProp$4 = Object.defineProperty;
2590
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2591
+ var __publicField$4 = (obj, key, value) => {
2592
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
2587
2593
  return value;
2588
2594
  };
2589
2595
  class MorphMany extends Relation {
@@ -2595,15 +2601,15 @@ class MorphMany extends Relation {
2595
2601
  /**
2596
2602
  * The field name that contains id of the parent model.
2597
2603
  */
2598
- __publicField$3(this, "morphId");
2604
+ __publicField$4(this, "morphId");
2599
2605
  /**
2600
2606
  * The field name that contains type of the parent model.
2601
2607
  */
2602
- __publicField$3(this, "morphType");
2608
+ __publicField$4(this, "morphType");
2603
2609
  /**
2604
2610
  * The local key of the model.
2605
2611
  */
2606
- __publicField$3(this, "localKey");
2612
+ __publicField$4(this, "localKey");
2607
2613
  this.morphId = morphId;
2608
2614
  this.morphType = morphType;
2609
2615
  this.localKey = localKey;
@@ -2660,10 +2666,10 @@ class MorphMany extends Relation {
2660
2666
  }
2661
2667
  }
2662
2668
 
2663
- var __defProp$2 = Object.defineProperty;
2664
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2665
- var __publicField$2 = (obj, key, value) => {
2666
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
2669
+ var __defProp$3 = Object.defineProperty;
2670
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2671
+ var __publicField$3 = (obj, key, value) => {
2672
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
2667
2673
  return value;
2668
2674
  };
2669
2675
  class HasManyThrough extends Relation {
@@ -2675,23 +2681,23 @@ class HasManyThrough extends Relation {
2675
2681
  /**
2676
2682
  * The "through" parent model.
2677
2683
  */
2678
- __publicField$2(this, "through");
2684
+ __publicField$3(this, "through");
2679
2685
  /**
2680
2686
  * The near key on the relationship.
2681
2687
  */
2682
- __publicField$2(this, "firstKey");
2688
+ __publicField$3(this, "firstKey");
2683
2689
  /**
2684
2690
  * The far key on the relationship.
2685
2691
  */
2686
- __publicField$2(this, "secondKey");
2692
+ __publicField$3(this, "secondKey");
2687
2693
  /**
2688
2694
  * The local key on the relationship.
2689
2695
  */
2690
- __publicField$2(this, "localKey");
2696
+ __publicField$3(this, "localKey");
2691
2697
  /**
2692
2698
  * The local key on the intermediary model.
2693
2699
  */
2694
- __publicField$2(this, "secondLocalKey");
2700
+ __publicField$3(this, "secondLocalKey");
2695
2701
  this.through = through;
2696
2702
  this.firstKey = firstKey;
2697
2703
  this.secondKey = secondKey;
@@ -2749,13 +2755,114 @@ class HasManyThrough extends Relation {
2749
2755
  }
2750
2756
  }
2751
2757
 
2758
+ var __defProp$2 = Object.defineProperty;
2759
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2760
+ var __publicField$2 = (obj, key, value) => {
2761
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
2762
+ return value;
2763
+ };
2764
+ class MorphToMany extends Relation {
2765
+ /**
2766
+ * Create a new morph to many to instance.
2767
+ */
2768
+ constructor(parent, related, pivot, relatedId, morphId, morphType, parentKey, relatedKey) {
2769
+ super(parent, related);
2770
+ /**
2771
+ * The pivot model.
2772
+ */
2773
+ __publicField$2(this, "pivot");
2774
+ /**
2775
+ * The field name that contains id of the parent model.
2776
+ */
2777
+ __publicField$2(this, "morphId");
2778
+ /**
2779
+ * The field name that contains type of the parent model.
2780
+ */
2781
+ __publicField$2(this, "morphType");
2782
+ /**
2783
+ * The associated key of the relation.
2784
+ */
2785
+ __publicField$2(this, "relatedId");
2786
+ /**
2787
+ * The key name of the parent model.
2788
+ */
2789
+ __publicField$2(this, "parentKey");
2790
+ /**
2791
+ * The key name of the related model.
2792
+ */
2793
+ __publicField$2(this, "relatedKey");
2794
+ /**
2795
+ * The key name of the pivot data.
2796
+ */
2797
+ __publicField$2(this, "pivotKey", "pivot");
2798
+ this.pivot = pivot;
2799
+ this.morphId = morphId;
2800
+ this.morphType = morphType;
2801
+ this.relatedId = relatedId;
2802
+ this.parentKey = parentKey;
2803
+ this.relatedKey = relatedKey;
2804
+ }
2805
+ /**
2806
+ * Get all related models for the relationship.
2807
+ */
2808
+ getRelateds() {
2809
+ return [this.related, this.pivot];
2810
+ }
2811
+ /**
2812
+ * Define the normalizr schema for the relationship.
2813
+ */
2814
+ define(schema) {
2815
+ return schema.many(this.related, this.parent);
2816
+ }
2817
+ /**
2818
+ * Attach the parent type and id to the given relation.
2819
+ */
2820
+ attach(record, child) {
2821
+ const pivot = child.pivot ?? {};
2822
+ pivot[this.morphId] = record[this.parentKey];
2823
+ pivot[this.morphType] = this.parent.$entity();
2824
+ pivot[this.relatedId] = child[this.relatedKey];
2825
+ child[`pivot_${this.relatedId}_${this.pivot.$entity()}`] = pivot;
2826
+ }
2827
+ /**
2828
+ * Convert given value to the appropriate value for the attribute.
2829
+ */
2830
+ make(elements) {
2831
+ return elements ? elements.map((element) => this.related.$newInstance(element)) : [];
2832
+ }
2833
+ /**
2834
+ * Match the eagerly loaded results to their parents.
2835
+ */
2836
+ match(relation, models, query) {
2837
+ const relatedModels = query.get(false);
2838
+ const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedId, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.morphId, this.getKeys(models, this.parentKey)).groupBy(this.morphId, this.relatedId, this.morphType).get();
2839
+ models.forEach((parentModel) => {
2840
+ const relationResults = [];
2841
+ relatedModels.forEach((relatedModel) => {
2842
+ const pivot = pivotModels[`[${parentModel[this.parentKey]},${relatedModel[this.relatedKey]},${this.parent.$entity()}]`]?.[0] ?? null;
2843
+ const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson(), { operation: void 0 });
2844
+ relatedModelCopy.$setRelation("pivot", pivot);
2845
+ if (pivot) {
2846
+ relationResults.push(relatedModelCopy);
2847
+ }
2848
+ });
2849
+ parentModel.$setRelation(relation, relationResults);
2850
+ });
2851
+ }
2852
+ /**
2853
+ * Set the constraints for the related relation.
2854
+ */
2855
+ addEagerConstraints(_query, _collection) {
2856
+ }
2857
+ }
2858
+
2752
2859
  var __defProp$1 = Object.defineProperty;
2753
2860
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2754
2861
  var __publicField$1 = (obj, key, value) => {
2755
2862
  __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2756
2863
  return value;
2757
2864
  };
2758
- class MorphToMany extends Relation {
2865
+ class MorphedByMany extends Relation {
2759
2866
  /**
2760
2867
  * Create a new morph to many to instance.
2761
2868
  */
@@ -2812,11 +2919,11 @@ class MorphToMany extends Relation {
2812
2919
  * Attach the parent type and id to the given relation.
2813
2920
  */
2814
2921
  attach(record, child) {
2815
- const pivot = child.pivot ?? {};
2816
- pivot[this.morphId] = record[this.parentKey];
2817
- pivot[this.morphType] = this.parent.$entity();
2818
- pivot[this.relatedId] = child[this.relatedKey];
2819
- child[`pivot_${this.pivot.$entity()}`] = pivot;
2922
+ const pivot = record.pivot ?? {};
2923
+ pivot[this.morphId] = child[this.relatedKey];
2924
+ pivot[this.morphType] = this.related.$entity();
2925
+ pivot[this.relatedId] = record[this.parentKey];
2926
+ child[`pivot_${this.relatedId}_${this.pivot.$entity()}`] = pivot;
2820
2927
  }
2821
2928
  /**
2822
2929
  * Convert given value to the appropriate value for the attribute.
@@ -2829,16 +2936,18 @@ class MorphToMany extends Relation {
2829
2936
  */
2830
2937
  match(relation, models, query) {
2831
2938
  const relatedModels = query.get(false);
2832
- const pivotModels = query.newQuery(this.pivot.$entity()).whereIn(this.relatedId, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.morphId, this.getKeys(models, this.parentKey)).groupBy(this.morphId, this.relatedId, this.morphType).get();
2939
+ const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedId, this.getKeys(models, this.parentKey)).whereIn(this.morphId, this.getKeys(relatedModels, this.relatedKey)).groupBy(this.relatedId, this.morphType).get();
2833
2940
  models.forEach((parentModel) => {
2834
2941
  const relationResults = [];
2835
- relatedModels.forEach((relatedModel) => {
2836
- const pivot = pivotModels[`[${parentModel[this.parentKey]},${relatedModel[this.relatedKey]},${this.parent.$entity()}]`]?.[0] ?? null;
2837
- const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson());
2838
- relatedModelCopy.$setRelation("pivot", pivot);
2942
+ const resultModelIds = this.getKeys(pivotModels[`[${parentModel[this.parentKey]},${this.related.$entity()}]`] ?? [], this.morphId);
2943
+ const relatedModelsFiltered = relatedModels.filter((filterdModel) => resultModelIds.includes(filterdModel[this.relatedKey]));
2944
+ relatedModelsFiltered.forEach((relatedModel) => {
2945
+ const pivot = (pivotModels[`[${parentModel[this.parentKey]},${this.related.$entity()}]`] ?? []).find((pivotModel) => pivotModel[this.morphId] === relatedModel[this.relatedKey]) ?? null;
2946
+ const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson(), { operation: void 0 });
2839
2947
  if (pivot) {
2840
- relationResults.push(relatedModelCopy);
2948
+ relatedModelCopy.$setRelation("pivot", pivot);
2841
2949
  }
2950
+ relationResults.push(relatedModelCopy);
2842
2951
  });
2843
2952
  parentModel.$setRelation(relation, relationResults);
2844
2953
  });
@@ -3024,7 +3133,7 @@ class Model {
3024
3133
  const pivotInstance = pivot.newRawInstance();
3025
3134
  parentKey = parentKey ?? model.$getLocalKey();
3026
3135
  relatedKey = relatedKey ?? instance.$getLocalKey();
3027
- this.schemas[related.entity][`pivot_${pivotInstance.$entity()}`] = new HasOne(instance, pivotInstance, relatedPivotKey, relatedKey);
3136
+ this.schemas[related.modelEntity()][`pivot_${relatedPivotKey}_${pivotInstance.$entity()}`] = new HasOne(instance, pivotInstance, relatedPivotKey, relatedKey);
3028
3137
  return new BelongsToMany(
3029
3138
  model,
3030
3139
  instance,
@@ -3044,7 +3153,7 @@ class Model {
3044
3153
  const pivotInstance = pivot.newRawInstance();
3045
3154
  parentKey = parentKey ?? model.$getLocalKey();
3046
3155
  relatedKey = relatedKey ?? instance.$getLocalKey();
3047
- this.schemas[related.entity][`pivot_${pivotInstance.$entity()}`] = new MorphOne(instance, pivotInstance, relatedId, model.$entity(), relatedKey);
3156
+ this.schemas[related.modelEntity()][`pivot_${relatedId}_${pivotInstance.$entity()}`] = new MorphOne(instance, pivotInstance, relatedId, model.$entity(), relatedKey);
3048
3157
  return new MorphToMany(
3049
3158
  model,
3050
3159
  instance,
@@ -3056,6 +3165,27 @@ class Model {
3056
3165
  relatedKey
3057
3166
  );
3058
3167
  }
3168
+ /**
3169
+ * Create a new MorphedByMany relation instance.
3170
+ */
3171
+ static morphedByMany(related, pivot, relatedId, id, type, parentKey, relatedKey) {
3172
+ const instance = related.newRawInstance();
3173
+ const model = this.newRawInstance();
3174
+ const pivotInstance = pivot.newRawInstance();
3175
+ parentKey = parentKey ?? model.$getLocalKey();
3176
+ relatedKey = relatedKey ?? instance.$getLocalKey();
3177
+ this.schemas[related.modelEntity()][`pivot_${relatedId}_${pivotInstance.$entity()}`] = new MorphOne(model, pivotInstance, id, type, relatedKey);
3178
+ return new MorphedByMany(
3179
+ model,
3180
+ instance,
3181
+ pivotInstance,
3182
+ relatedId,
3183
+ id,
3184
+ type,
3185
+ parentKey,
3186
+ relatedKey
3187
+ );
3188
+ }
3059
3189
  /**
3060
3190
  * Create a new HasMany relation instance.
3061
3191
  */
@@ -3283,7 +3413,7 @@ class Model {
3283
3413
  keyValue = mutator.set(keyValue);
3284
3414
  }
3285
3415
  if (cast && operation === "set") {
3286
- keyValue = cast.set(keyValue);
3416
+ keyValue = options.action === "update" ? cast.get(keyValue) : cast.set(keyValue);
3287
3417
  }
3288
3418
  this[key] = this[key] ?? keyValue;
3289
3419
  }
@@ -3522,6 +3652,9 @@ class Model {
3522
3652
  */
3523
3653
  serializeObject(value) {
3524
3654
  const obj = {};
3655
+ if (value.serialize && typeof value.serialize === "function") {
3656
+ return value.serialize(value);
3657
+ }
3525
3658
  for (const key in value) {
3526
3659
  obj[key] = this.serializeValue(value[key]);
3527
3660
  }