-
Notifications
You must be signed in to change notification settings - Fork 109
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
Insert on duplicate key upd when inserting a record? #635
Comments
Sorry, but I'm unclear on what the scenario is here. Can you provide more information - namely the Model relationships and the JSON:API Schema relationships? |
I think he has 3 objects:
I think he wants to connect some known days to some known warehouses using a many-to-many relation. Warehouse day is the pivot in here. As far as I know, I think he has the problem that the id is not unique when making a new Warehouse day as many-to-many relation. |
Yes, you said exactly right about the presence of these three entities: Table LegalEntityWarehouseDay has a composite unique key for fields LegalEntityWarehouseID and WarehouseDayID. |
Ok - you'd need to use validation to reject the request. I.e your validation needs to detect that the given combination of warehouse plus day already exists. The JSON:API package cannot do that itself, because it does not know that those two relationships on I.e. it is your business logic that says that that combination must not already exist - therefore your validation needs to pick up on it. |
I don't know, but isn't it an idea to make some helper functions to make validation of this kind a bit easier? |
Hmmm... I think maybe this fits into the whole topic of "many-to-many", which is causing people a lot of issues about how best to implement that. I need to sit down and actually work out what the "official" way of doing it is, then write some docs and implement any changes that are needed. It just hasn't bubbled to the top of my priorities yet as I haven't stumbled over the issue myself in any of my production apps. Though recognise that based on the number of questions I get about it, I probably need to sort this out relatively soon. |
Hi! This POST-request create row in many-to-many table:
In table
legal-entity-warehouse-days
has unique key (legal_entity_warehouse_id - warehouse_day_id
).If you send a post request several times, there will be an error duplicating a unique composite key.
How to fix it?
The text was updated successfully, but these errors were encountered: