Avoid the creation of the same record from a relationship
Hello everyone,
How can I avoid the creation of the same record from a relationship if it has not changed? In this way, prevent the same record from being generated repeatedly in the Edit functionalities.
It would be desirable to only delete the modified records (and create new records with the new values), delete those deleted records and create the new values. That is, if there was no modification, do not delete the records and create them again.
Thank you very much in advance!
14 Replies
Work Order:
Work Order Org Structure:
Work Order Resource:
}
Does anyone have any ideas?
Does anyone have any ideas? Thanks in advance !
not quite a filament question I suppose..
you could use an observer and on creation of said record check if there is already one with simular attributes.. or forcing certain columns to be unique is enough in most cases
Yes, I assume that it is a filament functionality since I use the "relationship" functionality to insert records into the "Work Order Org Structure" table from the "Work Order" resource.
I am going to try to manipulate the creation of records in the related tables but in my system I have many relationships and this would mean having to manually manipulate the creation of each of them
I dont see the issue then? the screenshot you provided has no duplicate records(one is soft deleted), filaments create action creates a records.. the edit action edits its.. nothing different than updating/creating it yourself?
The issue is that NO modifications are being made to the records. A record is being soft deleted and recreated again. This is giving me serious database sizing problems.
code?
besides this beeing a mess, this is not the action that is beeing ran.. are you using a createaction or just an action, did you change the create/update in the resource?
also using raw queries is a nono with eloquent imo but I aint gonna read alat
specify your question.. I cant read your mind and dont know your code
That is the code in my resource. then I DO NOT modify the insert in the related table since it is being resolved by the ">relationship('ProfileBusinessPartners')" functionality in the TableRepeater
The problem is as expressed above, when submitting the form, the "relationship()" functionality is reinserting a record that was NOT modified. It marks the existing record as soft deleted and generates its insertion again.
why not use a relation manager instead?
I am using TableRepeater to improve the user experience. The form has several steps and one of them is to select the necessary resources for the Work Order that is creating
it would be helpful to figure out when this occurs as I can use a repeater without any issues.. same goes with a relation manager
What other information could I provide you?
Pinpoint the problem, when does this occur? Is it with every model or just this one.. Etc