phly / PhlyRestfully

ZF2 module for creating RESTful JSON APIs using HAL and API-Problem
108 stars 45 forks source link

Child resource identification mapping to object #52

Closed macnibblet closed 11 years ago

macnibblet commented 11 years ago

Say we have a the following route /users/:id/comments/:comment_id The comments resource would have the identifier comment_id

But given the structure of my entity

class Comment
{
    public $id;
    public $user;
    public $comment;
}

The self link would fail due to the fact it searches the Comment object for comment_id when it's actually represented as id

weierophinney commented 11 years ago

Can you provide a full test case please? I'm having trouble fulling understanding the issue and coming up with a reproduce case.

macnibblet commented 11 years ago

@weierophinney ping

weierophinney commented 11 years ago

@macnibblet I'm having a hard time writing up a test case. Can you indicate how the controller would be configured with the above (are you calling setIdentifierName()? Is this happening when calling the collection of children, or retrieving a single child resource, or both?

weierophinney commented 11 years ago

@macnibblet Finally reproduced. The issue only happens with child collections. When dealing with a single child resource, the self link is created using the set identifier name in the controller, but with collections, this is not the case.

Now that I have a reproduce case, I should be able to fix it.

weierophinney commented 11 years ago

@macnibblet Can you try this patch, please?

Essentially, when returning a HalCollection from the ResourceController, I'm now passing it the identifier name as set in the controller. The HalLinks plugin then uses this to create the route parameters for the individual resource items in the collection, which generates the appropriate links.