@@ -311,7 +311,10 @@ public function updateRecordsOrderAndColumn($columnId, $cardIds): bool
311311 public function openCreateForm (string $ columnId ): void
312312 {
313313 $ this ->currentColumn = $ columnId ;
314- $ this ->resetCreateForm ();
314+ $ this ->recordData = [];
315+
316+ // Set the base model without filling yet
317+ $ this ->createRecordForm ->model ($ this ->adapter ->baseQuery ->getModel ());
315318
316319 // Pre-set the column field
317320 $ columnField = $ this ->config ->getColumnField ();
@@ -347,24 +350,27 @@ public function openEditForm(string|int $recordId, string|int $columnId): void
347350 return ;
348351 }
349352
350-
351- if (!$ this ->editRecordForm ->model ?->getKey()) {
352- info ('openEditForm ' , [
353- 'record ' => $ this ->editRecordForm ->model ?->getKey()
354- ]);
355-
356- $ this ->editRecordForm ->model ($ record );
357- }
358- $ this ->editRecordForm ->fill ($ record ->toArray ());
353+ // Set recordData first
359354 $ this ->recordData = $ record ->toArray ();
355+
356+ // Clear form state to avoid reactivity issues
357+ $ this ->editRecordForm ->fill ([]);
358+
359+ // Set the model on the form - this is crucial for relationships in nested components
360+ $ this ->editRecordForm ->model ($ record );
361+
362+ // Now fill the form, which will allow nested components to initialize with the model's relationships
363+ // Using the model's data directly instead of recordData to avoid reactivity loops
364+ $ this ->editRecordForm ->fill ($ record ->toArray ());
360365 }
361366
362367 /**
363368 * Create a new card.
364369 */
365370 public function createRecord (): void
366371 {
367- $ data = $ this ->createRecordForm ->getState ();
372+ // Use the combined recordData for creating the record
373+ $ data = $ this ->recordData ;
368374
369375 // Ensure column field is set
370376 $ columnField = $ this ->config ->getColumnField ();
@@ -400,14 +406,18 @@ public function createRecord(): void
400406 private function resetCreateForm (): void
401407 {
402408 $ this ->recordData = [];
403- $ this ->createRecordForm ->fill ();
409+ $ this ->currentColumn = null ;
410+
411+ // Just clear the form without chaining methods
412+ $ this ->createRecordForm ->fill ([]);
404413 }
405414
406415 /**
407416 * Update an existing card.
408417 */
409418 public function updateRecord (): void
410419 {
420+ // Use form state to get data with any relationship handling applied
411421 $ data = $ this ->editRecordForm ->getState ();
412422 $ record = $ this ->adapter ->getModelById ($ this ->currentRecord );
413423
@@ -448,7 +458,10 @@ public function updateRecord(): void
448458 public function resetEditForm (): void
449459 {
450460 $ this ->recordData = [];
451- $ this ->editRecordForm ->fill ();
461+ $ this ->currentRecord = null ;
462+
463+ // Just clear the form without chaining methods
464+ $ this ->editRecordForm ->fill ([]);
452465 }
453466
454467 /**
0 commit comments