api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.44k stars 868 forks source link

PUT and partial updates #134

Closed Drachenkaetzchen closed 9 years ago

Drachenkaetzchen commented 9 years ago

Consider this JSON fragment:

{
"name": "test1123",
  "prefixes":[ {
    "@id": "/~felicitus/PartKeepr/web/app_dev.php/api/si_prefixes/8",
  }]
}

In my installation, the bundle tries to create a new entity instead of loading the existing one specified by @id. According to the documentation here, this should work.

When I change my JSON to

{
"name": "test1123",
  "prefixes": [
       "/~felicitus/PartKeepr/web/app_dev.php/api/si_prefixes/8"
    ]
}

it works, but that prevents me from updating related objects, as they are always considered new.

dunglas commented 9 years ago

Do you send this JSON fragment trough a POST or a PUT request? Can you post your service definition and your entities (especially groups definition) to see what is going wrong?

Drachenkaetzchen commented 9 years ago

I'm using a PUT request, I haven't tested POST so far.

config.yml Unit.php SiPrefix.php

In the meanwhile, I tried different things like making properties public and removing getters/setters, but it didn't seem to work. Most likely a PEBCAK, but I couldn't figure it out. Thanks for your help!

dunglas commented 9 years ago

Thank you for the report, it was a bug! Fixed in master.

Drachenkaetzchen commented 9 years ago

Thank you for the quick fix, I can confirm that it works now.