@@ -95,6 +95,7 @@ abstract class Entity extends Model implements
9595 'name ' ,
9696 'slug ' ,
9797 'book_id ' ,
98+ 'chapter_id ' ,
9899 'priority ' ,
99100 'created_at ' ,
100101 'updated_at ' ,
@@ -104,13 +105,12 @@ abstract class Entity extends Model implements
104105 'owned_by ' ,
105106 ];
106107
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-
109108 /**
110109 * Override the save method to also save the contents for convenience.
111110 */
112111 public function save (array $ options = []): bool
113112 {
113+ /** @var EntityPageData|EntityContainerData $contents */
114114 $ contents = $ this ->relatedData ()->firstOrNew ();
115115 $ contentFields = $ this ->getContentsAttributes ();
116116
@@ -119,10 +119,13 @@ public function save(array $options = []): bool
119119 unset($ this ->attributes [$ key ]);
120120 }
121121
122+ $ this ->setAttribute ('type ' , $ this ->getMorphClass ());
122123 $ result = parent ::save ($ options );
123124 $ contentsResult = true ;
124125
125126 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 );
126129 $ contentsResult = $ contents ->save ();
127130 $ this ->touch ();
128131 }
@@ -446,7 +449,7 @@ public function logDescriptor(): string
446449 }
447450
448451 /**
449- * @return HasOne<EntityContainerContents|EntityPageContents , $this>
452+ * @return HasOne<EntityContainerData|EntityPageData , $this>
450453 */
451454 abstract public function relatedData (): HasOne ;
452455
0 commit comments