# Enforcing a Relationship when creating a Child Resource

**URL:** <https://discuss.jsonapi.org/t/enforcing-a-relationship-when-creating-a-child-resource/1301>\
**Category:** Uncategorized\
**Created:** [May 30, 2018, 3:10pm UTC](https://discuss.jsonapi.org/t/enforcing-a-relationship-when-creating-a-child-resource/1301 "2018-05-30T15:10:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mriffe](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/mriffe/32/545_2.png) [@mriffe](https://discuss.jsonapi.org/u/mriffe)\
**Post date:** [May 30, 2018, 3:10pm UTC](https://discuss.jsonapi.org/t/enforcing-a-relationship-when-creating-a-child-resource/1301/1 "2018-05-30T15:10:46Z")

</div>

Forgive me for the poorly-worded subject. But I have business logic that stipulates a child resource can not be created independent of its parent resource. I interpret this to mean when creating the child resource the supplied parameters MUST contain a valid relationship definition.

I’m assuming, as the writer of the server code, I need to enforce this business rule.

My Questions:

- Does this go against the specification?
- Is 400 Bad Request, with proper details of course, an adequate response?

Thank you.

---

<div class="post-metadata">

**Author:** ![michaelhibay](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/michaelhibay/32/405_2.png) [@michaelhibay](https://discuss.jsonapi.org/u/michaelhibay)\
**Post date:** [June 25, 2018, 7:21pm UTC](https://discuss.jsonapi.org/t/enforcing-a-relationship-when-creating-a-child-resource/1301/2 "2018-06-25T19:21:24Z")

</div>

You can use [compound documents](http://jsonapi.org/format/#document-compound-documents) to create them together.

---

<div class="post-metadata">

**Author:** ![mriffe](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/mriffe/32/545_2.png) [@mriffe](https://discuss.jsonapi.org/u/mriffe)\
**Post date:** [July 2, 2018, 5:15pm UTC](https://discuss.jsonapi.org/t/enforcing-a-relationship-when-creating-a-child-resource/1301/3 "2018-07-02T17:15:35Z")

</div>

Thank you for the feedback. I will explore compound documents more closely.

---

<div class="post-metadata">

**Author:** ![thexobbitt](https://avatars.discourse-cdn.com/v4/letter/t/35a633/32.png) [@thexobbitt](https://discuss.jsonapi.org/u/thexobbitt)\
**Post date:** [July 3, 2018, 8:38am UTC](https://discuss.jsonapi.org/t/enforcing-a-relationship-when-creating-a-child-resource/1301/4 "2018-07-03T08:38:11Z")

</div>

> <https://github.com/json-api/json-api/pull/1197>

  
This PR resolves your case.

---

<div class="post-metadata">

**Author:** ![mriffe](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/mriffe/32/545_2.png) [@mriffe](https://discuss.jsonapi.org/u/mriffe)\
**Post date:** [July 3, 2018, 2:32pm UTC](https://discuss.jsonapi.org/t/enforcing-a-relationship-when-creating-a-child-resource/1301/5 "2018-07-03T14:32:47Z")

</div>

Thanks for sharing the PR.
