@@ -38,27 +38,32 @@ func (e *ExtendedClient) FindRelated(entityName, referenceId, relationColumn str
3838 return result , nil
3939}
4040
41- // AddRelation associates a target entity with a source via a relationship .
42- // POST /api/{entity}/{referenceId}/{relationColumn}
41+ // AddRelation associates a target entity with a source via JSON:API relationships endpoint .
42+ // PATCH /api/{entity}/{referenceId}/relationships /{relationColumn}
4343func (e * ExtendedClient ) AddRelation (entityName , referenceId , relationColumn , targetType , targetRefId string ) error {
4444 body := map [string ]interface {}{
45- "data" : map [string ]interface {}{
46- "type" : targetType ,
47- "id" : targetRefId ,
45+ "data" : []map [string ]interface {}{
46+ {"type" : targetType , "id" : targetRefId },
4847 },
4948 }
5049
51- resp , err := e .nextRequest ().SetBody (body ).Post (
52- e .Endpoint + "/api/" + entityName + "/" + referenceId + "/" + relationColumn ,
50+ resp , err := e .nextRequest ().SetBody (body ).Patch (
51+ e .Endpoint + "/api/" + entityName + "/" + referenceId + "/relationships/ " + relationColumn ,
5352 )
5453 return e .checkResponse (resp , err )
5554}
5655
57- // RemoveRelation removes a relationship association.
58- // DELETE /api/{entity}/{referenceId}/{relationColumn}/{targetRefId}
59- func (e * ExtendedClient ) RemoveRelation (entityName , referenceId , relationColumn , targetRefId string ) error {
60- resp , err := e .nextRequest ().Delete (
61- e .Endpoint + "/api/" + entityName + "/" + referenceId + "/" + relationColumn + "/" + targetRefId ,
56+ // RemoveRelation removes a relationship association via JSON:API relationships endpoint.
57+ // DELETE /api/{entity}/{referenceId}/relationships/{relationColumn}
58+ func (e * ExtendedClient ) RemoveRelation (entityName , referenceId , relationColumn , targetType , targetRefId string ) error {
59+ body := map [string ]interface {}{
60+ "data" : []map [string ]interface {}{
61+ {"type" : targetType , "id" : targetRefId },
62+ },
63+ }
64+
65+ resp , err := e .nextRequest ().SetBody (body ).Delete (
66+ e .Endpoint + "/api/" + entityName + "/" + referenceId + "/relationships/" + relationColumn ,
6267 )
6368 return e .checkResponse (resp , err )
6469}
0 commit comments