src/Hydrator.php
private function convertRelationships(EntityMetadata $metadata, array $data)
    {
        foreach ($metadata->getRelationships() as $key => $relMeta) {
            if (!isset($data[$key])) {
                continue;
            }
            if (true === $relMeta->isMany() && !is_array($data[$key])) {
                throw PersisterException::badRequest(sprintf('Relationship key "%s" is a reference many. Expected record data type of array, "%s" found on model "%s" for identifier "%s"', $key, gettype($data[$key]), $type, $identifier));
            }
            $references = $relMeta->isOne() ? [$data[$key]] : $data[$key];

            $extracted = [];
            foreach ($references as $reference) {
                $extracted[] =  $this->extractRelationship($relMeta, $reference);
            }
            $data[$key] = $relMeta->isOne() ? reset($extracted) : $extracted;
        }
        return $data;
    }
private function convertRelationships(EntityMetadata $metadata, array $data)
    {
        foreach ($metadata->getRelationships() as $key => $relMeta) {
            if (!isset($data[$key])) {
                continue;
            }
            if (true === $relMeta->isMany() && !is_array($data[$key])) {
                throw PersisterException::badRequest(sprintf('Relationship key "%s" is a reference many. Expected record data type of array, "%s" found on model "%s" for identifier "%s"', $key, gettype($data[$key]), $type, $identifier));
            }
            $references = $relMeta->isOne() ? [$data[$key]] : $data[$key];

            $extracted = [];
            foreach ($references as $reference) {
                $extracted[] =  $this->extractRelationship($relMeta, $reference);
            }
            $data[$key] = $relMeta->isOne() ? reset($extracted) : $extracted;
        }
        return $data;
    }
private function convertRelationships ( EntityMetadata $ metadata , array $ data ) { foreach ( $ metadata -> getRelationships ( ) as $ key => $ relMeta ) { if ( ! isset ( $ data [ $ key ] ) ) { continue ; } if ( true === $ relMeta -> isMany ( ) && ! is_array ( $ data [ $ key ] ) ) { throw PersisterException :: badRequest ( sprintf ( 'Relationship key "%s" is a reference many. Expected record data type of array, "%s" found on model "%s" for identifier "%s"' , $ key , gettype ( $ data [ $ key ] ) , $ type , $ identifier ) ) ; } $ references = $ relMeta -> isOne ( ) ? [ $ data [ $ key ] ] : $ data [ $ key ] ; $ extracted = [ ] ; foreach ( $ references as $ reference ) { $ extracted [ ] = $ this -> extractRelationship ( $ relMeta , $ reference ) ; } $ data [ $ key ] = $ relMeta -> isOne ( ) ? reset ( $ extracted ) : $ extracted ; } return $ data ; }
Converts the relationships on a raw result to the proper format.

@param   EntityMetadata  $metadata
@param   array           &$data
@return  array
Converts the relationships on a raw result to the proper format .