-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
Description
Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?
- Yes, it's still reproducable
What version of Laravel Excel are you using?
3.1.63
What version of Laravel are you using?
11.43.2
What version of PHP are you using?
8.4
Describe your issue
Due to the ->save()
call in src/Imports/Persistence/CascadePersistManager.php:44
which happens before the relations are persisted it is not possible to use the PersistRelations
interface for relations which are required (NOT NULL).
How can the issue be reproduced?
- Create two models with a BelongsTo relation between them
- Make the relation
->foreignId(RelatedModel::class)->constrained()
(NOT NULL) - Create a
ToModel
import including$model->setRelation('related', new RelatedModel);
- Call
import
on the importer
What should be the expected behaviour?
I'd expect to either note in the docs that this is a limitation of the interface (a massive one) or that it'd not save the model before persisting the relations.