Relationship Issue

i have csv upload form , the function is to read the csv file and insert data in multiple table. i have three tables collections, sub_collections and manifests, manifest table contains collection_id and sub_collection_id and su_collections table contains collection_id every thing work perfect but the collection_id is not updated in sub_collections table
10 Replies
toeknee
toeknee2y ago
So we would need to see some code.
skpi4u
skpi4uOP2y ago
@toeknee this the create file for manifest
Patrick Boivin
@skpi4u This is a big chunk of code, and there's a lot happening in afterStateUpdated()... can you maybe simplify it to pinpoint your issue better? You're not really creating the sub_collection here, right?
skpi4u
skpi4uOP2y ago
@pboivin
Yes manifest table contains collection_id and sub_collection_id and sub_collections table contains collection_id every thing work perfect but the collection_id is not updated in sub_collections table this is code Forms\Components\Group::make([ TextInput::make('collection')->required(), ])->relationship('collections')->columnSpan('full'), Forms\Components\Group::make([ TextInput::make('sub_collection')->required(), ])->relationship('subCollections') ->columnSpan('full'),
Patrick Boivin
Why do you need the collection_id on the manifest if you have a sub_collection_id?
skpi4u
skpi4uOP2y ago
@pboivin collection_id is mapped with sub_collection table and when record created the collection_id become null in sub_collection table.
Patrick Boivin
Yes that's because you're never assigning the collection_id to the sub collection...
skpi4u
skpi4uOP2y ago
@pboivin Any solution to solve this issue
Patrick Boivin
I'm not sure I can help without seeing the rest of the code, the models, etc. If you really only need to add the collection_id to the sub collection, you can probably do it in a lifecycle hook, like afterCreate() : https://filamentphp.com/docs/2.x/admin/resources/creating-records#lifecycle-hooks
skpi4u
skpi4uOP2y ago
@pboivin I will try this tomorrow and let you know if it's work problem solve using afterCreate() :
Want results from more Discord servers?
Add your server