-
Notifications
You must be signed in to change notification settings - Fork 37
Can't return a collection object with embedded entities when content negotiation is set to Json #31
Conversation
I've been looking at the use case, as well as the code changes necessary, and I'm hitting some stumbling blocks. Essentially, my original idea was that you could return an object that composes a collection as a property, and zf-hal would serialize that. However, there are a few problems here:
My thought is this: allow I'm going to take this route now; let me know if you do not think this will work. |
- Modified `Resource::fetchAll()` to allow returning arbitrary objects - Modified `invalidCollection()` data provider to remove case using `stdClass`, as that case is invalidated. - Renamed `testFetchAllReturnsEmptyArrayIfLastListenerDoesNotReturnArrayOrTraversable` to `testFetchAllReturnsEmptyArrayIfLastListenerReturnsScalar` to clarify new intent.
- Actually, `ZF\Hal\Entity` allowed it previously; the new test passed even without changes. Simply modified the code to explicitly make the `$id` an optional argument.
- Do not return an ApiProblem in the case that an entity's identifier was not discovered. - Updated `injectSelfLink()` to not include null identifiers for entities.
- Modified `getList()` to look for non-array, non-`Traversable`, non-`ZF\Hal\Collection` object returns from `Resource::fetchAll()`, and to pass those to the `createEntity()` of the Hal plugin instead of `createCollection()`. - Updated `create()` to check for a null identifier on the returned entity and explicitly return an ApiProblem in that situation (the previous behavior).
Matthew, yes it sounds like it would work. I'll try it out in my implementation once it's ready, thanks! |
- Will change this to `>=1.0.2,<2.0` when zf-hal is tagged at 1.0.2.
@jdelisle Okay, changes are in both zf-hal and zf-rest. To test, modify your application's
|
@weierophinney I've tried exactly what you said, but for some reason composer returns me this:
|
@weierophinney Nevermind, I figured that one out:
|
@jdelisle cool -- let me know if this works for you! |
@weierophinney Ok, so I've been testing this a bit and here's what I get. See my gist here: https://gist.github.com/jdelisle/0fda5fee208ea35e9117 In If however I take out the entry for the collection class in the Am I not using it the way you intended? If so, could you provide me with a working example? |
- Updated zf-hal to 1.0.2 (to pick up required changes in the hal plugin)
Funny... just read zfcampus/zf-hal#38 (comment) and it seems related to what I've just described in my previous comment... |
Possible resolution as mentioned below:
Transcript from IRC: