Creating resource with its relations


#1

Hi there,

I’ve seen many posts where people are asking about creating resource with its relationships. Most common example is used this:

POST /photos HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "photos",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "relationships": {
      "photographer": {
        "data": { "type": "people", "id": "9" }
      }
    }
  }
}

What is clear to me: current version doesn’t support creating multiple relations, i.e.: photos with its photographer relationship and camera relationship, since it has two relationships in this case.
What is confusing me: would this request be a valid, to create many items in single relationship ( is ID mandatory? ):

POST /photos HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "photos",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "relationships": {
      "photographer": {
        "data": [
            { "type": "photographer", "id": "9", attributes: { "name" : "John" } },
            { "type": "photographer", attributes: { "name" : "Mike" } }
        ]
      }
    }
  }
}

What about if photographer has its own relationship?

References:



Thanks!