Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sideposting - associating same newly created record with multiple records that are also being created #435

Open
akshah123 opened this issue Sep 2, 2022 · 0 comments

Comments

@akshah123
Copy link

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?

@akshah123 akshah123 changed the title sideposting - associating same newly created record with multiple records sideposting - associating same newly created record with multiple records that are also being created Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant