-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fill deleting records on second order relation #15
Comments
Hi, Thanks for your analysis. I'll have a look at the PR and approve it once I understand the implications. |
Lads, has this PR been merged ? items has both "id" and "document_id" fields set, so technically should be possible to "update", but instead we're getting "delete" followed by "insert". Where some other table may have a foreign key to that items "id" this will become a problem. ` insert into details (id, document_id, position, material, description, quantity, units, updated_at, created_at) values (13046, 21082, '0010', 'BLAH', 'ALOHAMA', '10.00', 'EA', '2019-12-25 12:44:22', '2019-12-25 12:44:22'); ` |
@hugeps Have you found a solution? |
I've created my own repo, merged the PR above and "bobs yer uncle" it worked... Now, I'm behind tracking this repo... |
@hugeps mainly thanks for your immediate reply. It would appear that the PR has been merged on this repository but I've still some problems. These are my models and their structure:
This is the array that I try to pass to the
On saving, however, the informations of the Course model is correctly updated, while the surveys are instead deleted and re-entered, while i'm sending, as you can see, the ID to ensure that it is updated.. Do you have any idea why this is happening? Thank you very much |
How about you try make the parent id field fillable inside a child model ? just in case i.e. survey_id inside questions and so on... |
I've setted
|
@hugeps Removing the SoftDeletes seems to be the only solution. In this way the system will always delete and re-create, but will "overwrite" the ids thus keeping the references unchanged. It's a dirty and limiting solution, but perhaps the only one for the moment (?) |
i am calling the following code on my product object:
the part being filled looks like this:
the two relevant tables before the fill look like this:
and after like this:
it deleted my existing attributes, i thought i might be the on delete cascade from the foreign key (maybe you were deleting the attribute, adding it back in, then deleting the part, adding it back in and the attribute was being deleted due to the cascade, but i removed the foreign key and this still happened. only the new attribute is left in the table)
i'm not sure what is happening here, but i'm pretty sure it is not the correct behaviour.
some more info from the sql log:
whatever it is you are doing the sql is deleting the attributes and then trying to update the deleted attributes instead of inserting a new one.
you can see the statement it makes for parts is different:
in that case it inserts instead of updating, but for attributes it tries to update the existing ones it just deleted. i'll keep looking over the code to see why it's updating and not inserting (the delete and recreate is fine as long as it does parts then attributes which it seems to be doing, and insert is more correct here since the attribute it's trying to delete doesn't exist as it was deleted in the cascade, but it doesn't know that so it makes a kind of sense) i can tell where it does the delete, it stands out well enough, the update though...not so sure
ok, so after some work i have found if you change the line:
to
the problem goes away and it works fine.
what i think is happening is the line:
is calling fill on the object, which then calls fillHasOneOrManyRelation on the child object, which then saves and creates the parent object in the process, the parent object needs to have exists set to true after that or it will try to insert again and get a pk violation, which i'm thinking is what you were doing here, however you were using the existence of a key as an indicator that the record exists, but the extant attributes also had a key, however you had deleted them in an earlier line so they weren't extant at that point.
so what i did was check if the record had recently been added (since you had previously deleted it the only way it can be in the database is if it had been recently inserted)
i'll clone down your repository, make the changes and put in a pull request
The text was updated successfully, but these errors were encountered: