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
So we would need to see some code.
@toeknee this the create file for manifest
@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?@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'),
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'),
Why do you need the
collection_id
on the manifest if you have a sub_collection_id
?@pboivin collection_id is mapped with sub_collection table and when record created the collection_id become null in sub_collection table.
Yes that's because you're never assigning the collection_id to the sub collection...
@pboivin Any solution to solve this issue
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@pboivin I will try this tomorrow and let you know if it's work
problem solve using afterCreate() :