json-api icon indicating copy to clipboard operation
json-api copied to clipboard

Omitting id in ResourceObject

Open cincauhangus opened this issue 5 years ago • 5 comments

Is it possible to omit the id in ResourceObject when making a request to create a new resource? From the JSON API spec, it allows id to be omitted when creating resources.

cincauhangus avatar Oct 09 '20 10:10 cincauhangus

Good point. Looks like a missing feature.

f3ath avatar Oct 10 '20 16:10 f3ath

Implemented in #108. Please take a look at v2.2.0 and let me know if that works for you.

Example: https://github.com/json-api-php/json-api/blob/master/test/NewResourceObjectTest.php

f3ath avatar Oct 13 '20 00:10 f3ath

thank you, will check it out in a bit!

cincauhangus avatar Oct 13 '20 04:10 cincauhangus

I've tested it out and I believe it would work for a typical insert operation. However, I realised my current code is also not per spec as well as I have multiple new resources in the data object, e.g.

{
    data: [
        { /*new resource*/ },
        { /*new resource*/ }
    ]
}

I believe the correct method is to adopt the atomic extension. Do you have plans to support this extension?

cincauhangus avatar Oct 15 '20 13:10 cincauhangus

No such plans, but PRs are always welcomed. (I know, I'm super fast with my replies)

f3ath avatar Jul 27 '22 00:07 f3ath