Dealing with relationships via the API

Hello, all!

Using V11 API here.

So that you understand the scenario, I have a many to many relationship between two modules called Pet and Booking.

Currently I am serializing this relationship (to send over a POST request) by the following way:

 

floof_booking_floof_pet:

{ 'add': ['aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee','aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'] }

This creates the new booking with 2 pets linked to it. However I will have to update this at some point (with a PUT request), adding or removing pets, so I cannot simply send ADD again, right? Because I think this will ADD another relationship to them instead of overwriting whatever is already there.

I'd like a way to overwrite the relationships, so whenever I do a PUT request, I can simply send the new relationships. Is it possible?

Thanks a lot!

Parents Reply Children
  • Thanks for your answer, .

    I can add, create and remove records from the relationship with the PUT request, I would have to use the appropriate ACTION for it (add, delete, create).

    But to do so, I'd have to compare the previous state with the new state and then add / remove the relationships to fit the new state. Is there a way to simply overwrite the relationships? So that I just have to pass the new ones and don't worry about the old ones?

    Or even a way to empty the relationship? So I can ADD the new ones?