{"action":"created","issue":{"url":"https://api.github.com/repos/api-platform/core/issues/904","repository_url":"https://api.github.com/repos/api-platform/core","labels_url":"https://api.github.com/repos/api-platform/core/issues/904/labels{/name}","comments_url":"https://api.github.com/repos/api-platform/core/issues/904/comments","events_url":"https://api.github.com/repos/api-platform/core/issues/904/events","html_url":"https://github.com/api-platform/core/pull/904","id":199857995,"number":904,"title":"Nested data implementation /dummy/1/relatedDummies","user":{"login":"soyuka","id":1321971,"avatar_url":"https://avatars.githubusercontent.com/u/1321971?v=3","gravatar_id":"","url":"https://api.github.com/users/soyuka","html_url":"https://github.com/soyuka","followers_url":"https://api.github.com/users/soyuka/followers","following_url":"https://api.github.com/users/soyuka/following{/other_user}","gists_url":"https://api.github.com/users/soyuka/gists{/gist_id}","starred_url":"https://api.github.com/users/soyuka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soyuka/subscriptions","organizations_url":"https://api.github.com/users/soyuka/orgs","repos_url":"https://api.github.com/users/soyuka/repos","events_url":"https://api.github.com/users/soyuka/events{/privacy}","received_events_url":"https://api.github.com/users/soyuka/received_events","type":"User","site_admin":false},"labels":[{"id":167974000,"url":"https://api.github.com/repos/api-platform/core/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":453639309,"url":"https://api.github.com/repos/api-platform/core/labels/[RFR]%20Ready%20for%20Review","name":"[RFR] Ready for Review","color":"0e8a16","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":21,"created_at":"2017-01-10T15:52:21Z","updated_at":"2017-02-15T17:34:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/api-platform/core/pulls/904","html_url":"https://github.com/api-platform/core/pull/904","diff_url":"https://github.com/api-platform/core/pull/904.diff","patch_url":"https://github.com/api-platform/core/pull/904.patch"},"body":"| Q             | A\r\n| ------------- | ---\r\n| Bug fix?      | no\r\n| New feature?  | no\r\n| BC breaks?    | no (should not be any)\r\n| Deprecations? | no\r\n| Tests pass?   | yes\r\n| Fixed tickets | #634 - not really a fix but it's a start\r\n| License       | MIT\r\n| Doc PR        | /\r\n\r\n#### Note:\r\n\r\n~~I didn't implement the DataProvider yet! I'm just proposing those first changes to see if you have comments/improvements on the way I handled the nested behavior!~~\r\n\r\n#### Related issues/PR:\r\n\r\n#885\r\n#634\r\n\r\n#### What should this PR end up doing:\r\n\r\nAllow `/entity/{id}/association` operations when a flag on a resource's property is set. For example:\r\n\r\n```php\r\n\r\n/**\r\n * @ApiResource\r\n */\r\nclass Dummy {\r\n    /**\r\n     * @ApiProperty(subcollection=true) \r\n    */\r\n    public $relatedDummies; \r\n}\r\n```\r\n\r\n```\r\ncurl http://localhost/api/dummy/1/related_dummies\r\n```\r\n\r\nYou can chain those and have `/api/dummy/1/related_dummies/2/third_levels`.\r\n\r\n#### Changes:\r\n- Add `subcollection` (boolean) on the PropertyMetadata\r\n- Initialize a new class `ApiPlatform\\Util\\OperationTypes` (maybe the path isn't the best one, suggestions?) to ease the handling of operation types\r\n- NestedCollectionDataProvider\r\n\r\n#### TODO \r\n- [x] path customization through path resolvers (new method no breaks)\r\n- [x] it will help refactoring ApiLoader kinda messy right now\r\n- [x] query review\r\n- [x] tests tests tests"},"comment":{"url":"https://api.github.com/repos/api-platform/core/issues/comments/280080243","html_url":"https://github.com/api-platform/core/pull/904#issuecomment-280080243","issue_url":"https://api.github.com/repos/api-platform/core/issues/904","id":280080243,"user":{"login":"soyuka","id":1321971,"avatar_url":"https://avatars.githubusercontent.com/u/1321971?v=3","gravatar_id":"","url":"https://api.github.com/users/soyuka","html_url":"https://github.com/soyuka","followers_url":"https://api.github.com/users/soyuka/followers","following_url":"https://api.github.com/users/soyuka/following{/other_user}","gists_url":"https://api.github.com/users/soyuka/gists{/gist_id}","starred_url":"https://api.github.com/users/soyuka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soyuka/subscriptions","organizations_url":"https://api.github.com/users/soyuka/orgs","repos_url":"https://api.github.com/users/soyuka/repos","events_url":"https://api.github.com/users/soyuka/events{/privacy}","received_events_url":"https://api.github.com/users/soyuka/received_events","type":"User","site_admin":false},"created_at":"2017-02-15T17:34:00Z","updated_at":"2017-02-15T17:34:00Z","body":"Okay so OneToOne relations do work. But:\r\n\r\n1. I had to inverse the relation you gave me to have `/questions/1/answers`. Indeed, we can not identify the `question.answer` if it's not this side that has the identity column. \r\n2. Because I had sub**collections** in mind, the returning result will be a collection. Though on a OneToOne relation we know that we expect only one result. Therefore it should be an Item. This is wrong IMO in terms of metadata.\r\n3. The url, as shown above has `answers` plural, which is again wrong for this particular use case.\r\n\r\nI didn't wanted to support a kinda `SubItem` thing because I don't think it's worth it. With filters you could have almost the same result through the origin item, here `Question` really easily.\r\n\r\nSo, what should we do about this? \r\n- Option 1: Prevent subcollections on OneToOne relations (ie throw an exception).\r\n- Option 2: Support subitem retrieval to have a clean url and proper Item metadata (eg hydra item vs collection) + Option 1\r\n- Option 3 : Do nothing, OneToOne works (only one way and throws a weird error that will make beginners panic the other way) but returns a collection.\r\n\r\nI'm not publishing the behat test yet but it's done thanks for the example classes @lbarulski ."}}
{"actor":{"display_login":"soyuka"}}