Import action - fill relationship hasone

Hey all, I'm trying to import a CSV that has a price relationship (hasOne). This is how I'm trying to do it:
ImportColumn::make('price')
->fillRecordUsing(function (Product $record, string $state): void {
$record->price_id = $record->price()->create([
'price' => $state,
'type' => 'one_time',
])->id;
})
->integer(),
ImportColumn::make('price')
->fillRecordUsing(function (Product $record, string $state): void {
$record->price_id = $record->price()->create([
'price' => $state,
'type' => 'one_time',
])->id;
})
->integer(),
Thing is, obviously, the $record->price can't be created because the record hasn't been assigned an ID yet. How can I approach this? Is it even possible with the Import action?
1 Reply
Diogo Pinto
Diogo Pinto3mo ago
I'm considering going with afterCreate // afterUpdate, but was wondering if there was a more direct approach.