Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self links of resources with custom identifier are not added when rendering a collection #123

Closed
codeliner opened this issue Mar 30, 2014 · 2 comments

Comments

@codeliner
Copy link
Contributor

I have a DTO coming from my domain that is used as resource. It implements getArrayCopy() and I use the ArraySerializable hydrator.
The resource has a custom identifier tracking_id. If the DTO is returned by ResourceListener#onFetch the resource contains a self link as expected. If
ResourceListener#onFetchAll returns a collection of DTOs the resources in the response do not contain self links.
Here is my configuration:

//routing:

'api' => array(
    'type' => 'Literal',
    'options' => array(
        'route'      => '/api',
    ),
    'may_terminate' => false,
    'child_routes' => array(
        'cargoroutings' => array(
            'type' => 'Segment',
            'options' => array(
                'route'      => '/cargoroutings[/:tracking_id]',
                'constraints' => array(
                    'tracking_id' => '[a-zA-Z0-9-]*',
                ),
                'defaults' => array(
                    'controller' => 'Api\Controller\CargoRoutings',
                ),

            ),
        )
    )
),

//phlyrestfully:
'phlyrestfully' => array(
    'resources' => array(
        'Api\Controller\CargoRoutings' => array(
            'listener' => 'cargo_routing_resource',
            'route_name' => 'api/cargoroutings',
            'identifier_name' => 'tracking_id',
            'collection_name' => 'cargoroutings',
        )
    ),
    'renderer' => array(
        'default_hydrator' => 'ArraySerializable'
    ),
    'metadata_map' => array(
        'CargoBackend\API\Booking\Dto\CargoRoutingDto' => array(
            'hydrator'        => 'ArraySerializable',
            'identifier_name' => 'tracking_id',
            'route'           => 'api/cargoroutings',
        )
    ),
),

//ArrayCopy of my DTO:
return array(
    'tracking_id'      => $this->getTrackingId(),
    'origin'           => $this->getOrigin(),
    'finalDestination' => $this->getFinalDestination(),
    'legs'             => $legsArrayCopy
);

I know, I can listen to the getIdFromResource event and extract the tracking_id by hand, but I think the configuration should be enough. Did I miss something?

weierophinney added a commit that referenced this issue May 26, 2016
@codeliner
Copy link
Contributor Author

That's nice: Two years later the issue got solved. In the meanwhile I switched to Apigility and then to zend-expressive :) Anyway, thank you @weierophinney

@andrewscaya
Copy link
Contributor

@codeliner

Alexander --

It's all my fault. ;-)

The module got updated in the context of an extended class project in my Zend Framework 2 Advanced class over at Zend. Sorry for the confusion! :-)

Cheers,

Andrew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants