laminas-api-tools / api-tools-hal

Laminas Module providing Hypermedia Application Language assets and rendering
https://api-tools.getlaminas.org/documentation
BSD 3-Clause "New" or "Revised" License
6 stars 12 forks source link

Entity identifier other than 'id' does not generate self link in collection #5

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

If I set 'entity_identifier_name' => 'code' then the links to the entities are not generated when fetching the collection. The link is generated when fetching an entity only.

Following the code at https://groups.google.com/a/zend.com/forum/#!msg/apigility-users/p4BWDl9oiIM/YnitOfkEAfUJ will now provide an entry for all properties in the entity. Obviously not a good response since these properties are not set when fetching a collection.

I have tried poking around in the code, and in ZF\Hal\Plugin\Hal::setEventManager() it seems to be hardcoded looking for 'id' (lines 168/169). If I hack this to 'code' then it populates just fine.

In the meantime, I have hooked into the 'getIdFromEntity' listener and made an ugly hack to try to extract this key.


Originally posted by @vorgas at https://github.com/zfcampus/zf-hal/issues/166

weierophinney commented 4 years ago

I agree that this should be possible. We also had to make a workaround.


Originally posted by @Wilt at https://github.com/zfcampus/zf-hal/issues/166#issuecomment-308102959