JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Nested attributes for relationships

Open
#424 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

If I were updating / creating a "post" and I also wanted to create / update tag id 3 in the example below, should that be possible (i.e. similar to nested attributes in active record).

Probably a bit of a bad example, but hopefully you get the idea ?

I am finding that each entry in "data" in the relationships must only contain id and type. Nowhere have I yet seen how to do this in json_api in general, not just in this gem so maybe it is not possible. In which case, I guess I would need to create / update the tag seperately, but then I may need to worry about rolling it back if the creation / update of the post did not succeed etc...

post '/posts',
  {
    'posts' => {
      'attributes' => {
        'title' => 'A great new Post'
      },
      'relationships' => {
        'tags' => {
          'data' => [
              {type: 'tags', id: 3, attributes: {name: "New Tag Name"}},
              {type: 'tags', id: 4}
            ]
        }
      }
    }
  }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file, test, or entry point is named. Start by reviewing the existing relationship create/update handling and the JSON:API rules for relationship data, then establish whether nested attributes are supported. Done should be a clear decision with defined request behavior and transaction or rollback expectations.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.