PUT request to append to relationship field, without supplying existing items?

Is it possible to make a PUT request via the strapi REST API that lets me update a many to many relationship field by just supplying the id I want to add… without supplying all the existing ids?

Currently doing this:

const heart = await fetch(url, {
method: ‘PUT’,
headers: {
‘Authorization’: Bearer ${jwt},
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
“data”: {
“HeartedBy”: [uid],
}
})
})

HeartedBy is a list of user ids who have hearted that item. But each time I do it, the current user just overwrites the previous user. I want to obviously continue to add to the list. Do I have to fetch all the current HeartedBy values every time I want to add to this so that I’m always supplying the whole list?

This topic has been created from a Discord post (1250905017272107080) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

You can use connect/disconnect but it’s easier to supply full array

Connect seems to be exactly what I need, but I’m having second thoughts since you mentioned it would be easier to supply the full array.

In my case, a user is basically “liking” a post. Wouldn’t it be worse all around if I had to query the post for all users who previously liked the post, and then add my new user onto that, and then do another call to update the whole array? I also worry about situations where 2 users would click “like” at the same time, they’d both query the existing likes, they’d both append only their id, and because of various syncing issues their could be data loss.

The updates are concurrent, but for likes I guess it’s connect is a way

Ok I appreciate your quick replies thank you!