public function relation($field)
    {
        $associations = $this->associations();
        if (empty($associations['manyToOne'])) {
            return false;
        }

        $data = $this->getContext();
        if (empty($data)) {
            return false;
        }

        foreach ($associations['manyToOne'] as $alias => $details) {
            if ($field !== $details['foreignKey']) {
                continue;
            }

            $entityName = $details['entity'];
            if (empty($data->$entityName)) {
                return false;
            }

            $entity = $data->$entityName;

            return [
                'alias' => $alias,
                'output' => $this->Html->link($entity->{$details['displayField']}, [
                    'plugin' => $details['plugin'],
                    'controller' => $details['controller'],
                    'action' => 'view',
                    $entity->{$details['primaryKey']}
                ])
            ];
        }

        return false;
    }
public function relation($field)
    {
        $associations = $this->associations();
        if (empty($associations['manyToOne'])) {
            return false;
        }

        $data = $this->getContext();
        if (empty($data)) {
            return false;
        }

        foreach ($associations['manyToOne'] as $alias => $details) {
            if ($field !== $details['foreignKey']) {
                continue;
            }

            $entityName = $details['entity'];
            if (empty($data->$entityName)) {
                return false;
            }

            $entity = $data->$entityName;

            return [
                'alias' => $alias,
                'output' => $this->Html->link($entity->{$details['displayField']}, [
                    'plugin' => $details['plugin'],
                    'controller' => $details['controller'],
                    'action' => 'view',
                    $entity->{$details['primaryKey']}
                ])
            ];
        }

        return false;
    }
public function relation ( $ field ) { $ associations = $ this -> associations ( ) ; if ( empty ( $ associations [ 'manyToOne' ] ) ) { return false ; } $ data = $ this -> getContext ( ) ; if ( empty ( $ data ) ) { return false ; } foreach ( $ associations [ 'manyToOne' ] as $ alias => $ details ) { if ( $ field !== $ details [ 'foreignKey' ] ) { continue ; } $ entityName = $ details [ 'entity' ] ; if ( empty ( $ data -> $ entityName ) ) { return false ; } $ entity = $ data -> $ entityName ; return [ 'alias' => $ alias , 'output' => $ this -> Html -> link ( $ entity -> { $ details [ 'displayField' ] } , [ 'plugin' => $ details [ 'plugin' ] , 'controller' => $ details [ 'controller' ] , 'action' => 'view' , $ entity -> { $ details [ 'primaryKey' ] } ] ) ] ; } return false ; }
Returns a formatted relation output for a given field

@param string $field Name of field.
@return mixed Array of data to output, false if no match found
Returns a formatted relation output for a given field