Hello,
We use jsonapi-resources gem for our Ruby on Rails API, which implements json:api, apologies if this is the wrong place to ask but I think the issue is bigger than the implementation. I am having trouble finding anything online in either json api or json api resources.
Our situation is that we have table A, table B, and a psuedo join table C (having C.a_id and C.b_id). C also has a number of other fields of information which is why I call it a psuedo join table. So to create a C we can send a POST to example.com/C
with the following data:
data: {
type: 'C',
attributes:{...},
relationships: {
B: {data:{type and id}},
A: {data:{type and id}}
}
},
Or we can send a POST to example.com/A/:id/relationships/C
with:
data: [{
type: 'B',
id: B.id
}]
The first option works fine but there is an internal request that the second is the proper way to do it. The second option, at least as far as I can tell, does not allow you set attributes, is that true? Also as this ‘join’ table will be historical (as in we will want to pull data over time for it), we need to create new entries every time. Currently Im getting an error ‘Relation exists’ when I try the second method, not sure if that is json api or the resources gem we are using. Is there a way around that? What would be the proper recommended way to save these values?
Thanks for your time,
Carl