@@ -32,6 +32,12 @@ abstract class BaseModel extends Model
32
32
public static $ snakeAttributes = false ;
33
33
public BaseModelAttributes $ a ;
34
34
public BaseModelRelations $ r ;
35
+ protected const A = 'a ' ;
36
+ protected const R = 'r ' ;
37
+ /**
38
+ * @var array<string, <string, string>>
39
+ */
40
+ protected static array $ activeRecordFqnSegregationPropertiesFqnsMap = [];
35
41
protected bool $ returnNullOnInvalidColumnAttributeAccess = true ;
36
42
protected array $ ignoreUpdateFor = [];
37
43
protected array $ ignoreExternalCreateFor = [];
@@ -51,7 +57,7 @@ public function __construct(array $attributes = [])
51
57
52
58
$ this ->initializeActiveRecordSegregationProperties ();
53
59
54
- $ this ->append ( 'primary_key_identifier ' ) ;
60
+ $ this ->appends [] = 'primary_key_identifier ' ;
55
61
}
56
62
57
63
public static function resourceName (): string
@@ -435,20 +441,30 @@ protected function incrementOrDecrement($column, $amount, $extra, $method): int
435
441
*/
436
442
protected function initializeActiveRecordSegregationProperties (): void
437
443
{
438
- $ prefix = \substr ($ class = static ::class, 0 , $ l = (-1 * (\strlen ($ class ) - \strrpos ($ class , '\\' ) - 1 ))) .
444
+ $ class = static ::class;
445
+
446
+ if (isset (self ::$ activeRecordFqnSegregationPropertiesFqnsMap [$ class ])) {
447
+ $ this ->a = new (self ::$ activeRecordFqnSegregationPropertiesFqnsMap [$ class ][self ::A])($ this );
448
+ $ this ->r = new (self ::$ activeRecordFqnSegregationPropertiesFqnsMap [$ class ][self ::R])($ this );
449
+
450
+ return ;
451
+ }
452
+
453
+ $ prefix = \substr ($ class , 0 , $ l = (-1 * (\strlen ($ class ) - \strrpos ($ class , '\\' ) - 1 ))) .
439
454
'Attributes \\' . \substr ($ class , $ l );
440
455
441
- foreach (
442
- [
443
- 'a ' => ['p ' => 'Attributes ' , 'c ' => BaseModelAttributes::class],
444
- 'r ' => ['p ' => 'Relations ' , 'c ' => BaseModelRelations::class]
445
- ] as $ p => $ propertyMap
446
- ) {
456
+ foreach ([self ::A => 'Attributes ' , self ::R => 'Relations ' ] as $ property => $ postfix ) {
447
457
try {
448
- $ this ->$ p = new ($ prefix . $ this ->$ propertyMap [ ' p ' ] )($ this );
458
+ $ this ->$ property = new ($ classFqn = $ prefix . $ this ->$ postfix )($ this );
449
459
} catch (\Throwable ) {
450
- $ this ->$ p = new ($ this ->$ propertyMap ['c ' ])($ this );
460
+ $ this ->$ property =
461
+ new ($ classFqn = 'MacropaySolutions\LaravelCrudWizard\Models\Attributes\BaseModel ' .
462
+ $ this ->$ postfix )(
463
+ $ this
464
+ );
451
465
}
466
+
467
+ self ::$ activeRecordFqnSegregationPropertiesFqnsMap [$ class ][$ property ] = $ classFqn ;
452
468
}
453
469
}
454
470
}
0 commit comments