I am implementing a user “bookmarks” feature. I have the User table with relation “user has many bookmarks”, and a “bookmarks” collection type which has relation “bookmark has exactly one user”. I am trying to use the REST API to update the User and bookmark tables when a client bookmarks a page in my site. The first call looks like:
The response is 200 OK, with the user record returned in the response. Examining the “bookmarks” field (many-to-one relation) indicates that the new bookmark was NOT added as expected. The PUT request above did not update the Users table. I have tried “set” in the above request instead of “connect” with the same result, and all the combinations of arrays, integer versus string, all to no effect. Relations | Strapi Documentation suggests the above syntax is correct?
First question - am I going about this in the best way, making two REST API calls to achieve the desired result?
Second question - if this is indeed how I need to do this, why is the second call having no effect on the user record? I have checked permissions for updates on the user table, and these are all as expected. I get no errors (e.g. 403 FORBIDDEN).
Further experimentation revealed that removing the {data:…} wrapper from the PUT request payload seems to achieve what is required. This is contradicting the documentation however.
I am having the same issue but when I remove the data property I get a validation error. What version of Strapi are you using and have you been able to get this to work consistently?
Any insight is much appreciated!! I’ve been running circles on this for hours now
I also am hitting this nasty wall. Does not work in any combo - disconnect/connect, set, no set (direct array or single value usage) - nothing. Just does not save - any relation (1:1 and 1:n). Even more - in my case it does not work with POST or PUT. Very very nasty issue which gives me headaches for 3 days now - docs are clear but behavior is just not as described.
@ITLackey did you try to report this as a bug (because it sure seems like one)?
I would have to check, but I believe part (or all) of the issue was permissions for the related entities. I had not granted the authenticated role permissions to the child entities only the parent. Changing the permissions allowed the update to work if I remember correctly.
OMG - now I feel like an idiot That did not occur to me at all - especially since my record is in fact related to itself (a recursive relation). I added find/findOne/update/create (I will play around to see which minimum set is really needed) to Authorized role and now it works. Damn