# AshJsonApi: Create relationship when creating resource

**URL:** <https://forum.elixirforum.com/t/ashjsonapi-create-relationship-when-creating-resource/60040>\
**Category:** Questions\
**Tags:** ash\
**Created:** [November 29, 2023, 8:51pm UTC](https://forum.elixirforum.com/t/ashjsonapi-create-relationship-when-creating-resource/60040 "2023-11-29T20:51:24Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![gordoneliel](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gordoneliel/32/30383_2.png) [@gordoneliel](https://forum.elixirforum.com/u/gordoneliel)\
**Post date:** [November 29, 2023, 11:47pm UTC](https://forum.elixirforum.com/t/ashjsonapi-create-relationship-when-creating-resource/60040/3 "2023-11-29T23:47:34Z")

</div>

> [@zachdaniel](#):
>
> `relationship`

I did try that with #1.

```json
{
  data: {
   attributes: {...attributes},
   relationships: {
     authors: [{type: "author", name: "Eliel", email: "q232"}]
   }
  }
}

```

This got somewhere but seems to need an `id` attribute in the relationship. When I add that none of the other attributes in the relationship make it to the changeset attributes under `authors`.

The other way was to put the relationship in the attributes

```json
{
  data: {
   attributes: {
    ...attributes,
    authors: [{name: "Eliel", email: "q232"}]
   },
  }
}

```

This did not work either, gave a invalid attribute error

---

_[View the full topic](https://forum.elixirforum.com/t/ashjsonapi-create-relationship-when-creating-resource/60040)._
