How do I render embedded objects in Apigility? For example, if I have a 'user' object and it composes a 'country' object, should I be rendering the 'country' object as an embedded object? And how should I do this?
I am using the Zend\Stdlib\Hydrator\ArraySerializable
. My getArrayCopy()
method simply returns an array of properties that I want exposed. The array keys are the property names. The array values are the property values. In the case of user->country
, the value is an object, not a scalar.
When I return the user object from UserResource->fetch()
, here's how it is rendered:
{
"id": "1",
"firstName": "Joe",
"lastName": "Bloggs",
"status": "Active",
"email": "test@example.com",
"country": {
"code": "AU",
"name": "Australia"
},
"settings": "0",
"_links": {
"self": {
"href": "http://api.mydomain.local/users/1"
}
}
}
Note that 'country' is not in an _embedded
field. If it is supposed to be in _embedded
, I would have thought that Apigility would automatically do that (since it automatically adds the _links
object).
As a related issue, how do I go about returning other rel links, such as back, forward, etc?