I have a usecase with sidepost where I would multiple records to reference a new record that's being created.
An example setup would be:
class ModelA
has_many :model_b
end
class ModelB
belongs_to :model_a
has_many :model_c
end
class ModelC
belongs_to :model_b
belongs_to :model_a
end
Now, i would like to create three object(s). 1 ModelA, 1 ModelB that belongs to ModelA and 1 ModelC that belongs to A & B.
I am trying following POST:
{
"data": {
"temp-id": "aaaa",
"type": "model_a",
"attributes": {
"street_and_number": "test_model_a"
},
"relationships": {
"model_b": {
"data": [
{
"type": "model_b",
"temp-id": "1a1a1a",
"method": "create"
}
]
}
}
},
"included": [
{
"type": "model_b",
"temp-id": "1a1a1a",
"attributes": {
"name": "test location"
},
"relationships": {
"model_c": {
"data": [
{
"type": "model_c",
"temp-id": "2b2b2b",
"method": "create"
}
]
}
}
},
{
"type": "model_c",
"temp-id": "2b2b2b",
"attributes": {},
"relationships": {
"model_a": {
"data": {
"type": "model_a",
"temp-id": "aaaa",
"method": "create"
}
}
}
}
]
}
However, above setup seems to create duplicate records for ModelA. How would I set this up so that I am not creating duplicate records while keeping it a single API call?
I have a usecase with sidepost where I would multiple records to reference a new record that's being created.
An example setup would be:
Now, i would like to create three object(s). 1 ModelA, 1 ModelB that belongs to ModelA and 1 ModelC that belongs to A & B.
I am trying following POST:
{ "data": { "temp-id": "aaaa", "type": "model_a", "attributes": { "street_and_number": "test_model_a" }, "relationships": { "model_b": { "data": [ { "type": "model_b", "temp-id": "1a1a1a", "method": "create" } ] } } }, "included": [ { "type": "model_b", "temp-id": "1a1a1a", "attributes": { "name": "test location" }, "relationships": { "model_c": { "data": [ { "type": "model_c", "temp-id": "2b2b2b", "method": "create" } ] } } }, { "type": "model_c", "temp-id": "2b2b2b", "attributes": {}, "relationships": { "model_a": { "data": { "type": "model_a", "temp-id": "aaaa", "method": "create" } } } } ] }However, above setup seems to create duplicate records for ModelA. How would I set this up so that I am not creating duplicate records while keeping it a single API call?