@@ -95,6 +95,7 @@ abstract class Entity extends Model implements
95
95
'name ' ,
96
96
'slug ' ,
97
97
'book_id ' ,
98
+ 'chapter_id ' ,
98
99
'priority ' ,
99
100
'created_at ' ,
100
101
'updated_at ' ,
@@ -104,13 +105,12 @@ abstract class Entity extends Model implements
104
105
'owned_by ' ,
105
106
];
106
107
107
- // TODO - Review usages of query-time update or mass insert of entity model data since those will still need to consider the multi-table layout.
108
-
109
108
/**
110
109
* Override the save method to also save the contents for convenience.
111
110
*/
112
111
public function save (array $ options = []): bool
113
112
{
113
+ /** @var EntityPageData|EntityContainerData $contents */
114
114
$ contents = $ this ->relatedData ()->firstOrNew ();
115
115
$ contentFields = $ this ->getContentsAttributes ();
116
116
@@ -119,10 +119,13 @@ public function save(array $options = []): bool
119
119
unset($ this ->attributes [$ key ]);
120
120
}
121
121
122
+ $ this ->setAttribute ('type ' , $ this ->getMorphClass ());
122
123
$ result = parent ::save ($ options );
123
124
$ contentsResult = true ;
124
125
125
126
if ($ result && $ contents ->isDirty ()) {
127
+ $ contentsFillData = $ contents instanceof EntityPageData ? ['page_id ' => $ this ->id ] : ['entity_id ' => $ this ->id , 'entity_type ' => $ this ->getMorphClass ()];
128
+ $ contents ->forceFill ($ contentsFillData );
126
129
$ contentsResult = $ contents ->save ();
127
130
$ this ->touch ();
128
131
}
@@ -446,7 +449,7 @@ public function logDescriptor(): string
446
449
}
447
450
448
451
/**
449
- * @return HasOne<EntityContainerContents|EntityPageContents , $this>
452
+ * @return HasOne<EntityContainerData|EntityPageData , $this>
450
453
*/
451
454
abstract public function relatedData (): HasOne ;
452
455
0 commit comments