Skip to content

Denormalization behavior with embedded models #1

Open
@backbone87

Description

@backbone87

Lets assume we have entity Book and Chapter. We will treat this as a 1-1 relation, but this also applies to 1-n relations.
`
(i will use yaml serialization for comments)

We asume that we have 1 book and 2 chapters already and that one chapter is related to book (1-1 remember).

"@id": /books/great-book
"@type": type:Book
title: A Great Book
content: /chapters/first-chapter
"@id": /chapters/first-chapter
"@type": type:Chapter
headline: The Beginning
"@id": /chapters/second-chapter
"@type": type:Chapter
headline: Continue

The context

type: http://example.com/
title: http://example.com/title
content:
  "@id": http://example.com/content
  "@type": @id
headline: http://example.com/headline

There are actually several different possibilities when updating the Book with an embedded update.
We do a PUT /books/great-book with the following documents

"@id": /books/great-book # can be infered by endpoint
"@type": Book # can be infered by endpoint
content:
  "@id": /chapters/first-chapter
  headline: Lets Start

Meaning:

  • Relate /books/great-book with content of /chapters/first-chapter. This is a noop
  • Update /chapter/first-chapter with headline of Lets Start (old value was The Beginning)
"@id": /books/great-book # can be infered by endpoint
"@type": Book # can be infered by endpoint
title: A Great Book
content:
  "@id": /chapters/second-chapter
  headline: Going On

Meaning:

  • Relate /books/great-book with content of /chapters/second-chapter.
  • Update /chapters/second-chapter with headline of Going On
"@id": /books/great-book # can be infered by endpoint
"@type": Book # can be infered by endpoint
title: A Great Book
content:
  "@id": /chapters/new-chapter
  headline: Finish

Meaning:

  • Relate /books/great-book with content of /chapters/new-chapter. But this chapter doesnt exist. Should it be created, or should the denormalization fail? (failing results in 400, 404 or 409 depending on preference)
  • If we created the /chapters/new-chapter we set its headline to Finish
"@id": /books/great-book # can be infered by endpoint
"@type": Book # can be infered by endpoint
content:
  headline: Lets start

Meaning:

  • the given chapter is a blank node and gets a blank id of _:1
  • Obviously there is no chapter _:1. we have 3 possibilities
    • Create a new chapter (and update it)
    • Fail (400, 404, 409)
    • Use whatever chapter is currently set as content of the book and update this (fails if there is no current content)

While the first 2 examples are pretty straight forward, the last two can get wonky.

@soyuka Whats your opinion on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions