src/FieldHandlers/RelatedFieldTrait.php
protected function _getAssociatedRecord(Table $table, string $value) : EntityInterface
    {
        $primaryKey = $table->getPrimaryKey();
        if (! is_string($primaryKey)) {
            throw new UnsupportedPrimaryKeyException();
        }

        // try to fetch with trashed if finder method exists, otherwise fallback to find all
        $finderMethod = $table->hasBehavior('Trash') ? 'withTrashed' : 'all';

        $entity = $table->find($finderMethod, ['conditions' => [$table->aliasField($primaryKey) => $value]])
            ->enableHydration(true)
            ->firstOrFail();
        Assert::isInstanceOf($entity, EntityInterface::class);

        return $entity;
    }
protected function _getAssociatedRecord(Table $table, string $value) : EntityInterface
    {
        $primaryKey = $table->getPrimaryKey();
        if (! is_string($primaryKey)) {
            throw new UnsupportedPrimaryKeyException();
        }

        // try to fetch with trashed if finder method exists, otherwise fallback to find all
        $finderMethod = $table->hasBehavior('Trash') ? 'withTrashed' : 'all';

        $entity = $table->find($finderMethod, ['conditions' => [$table->aliasField($primaryKey) => $value]])
            ->enableHydration(true)
            ->firstOrFail();
        Assert::isInstanceOf($entity, EntityInterface::class);

        return $entity;
    }
protected function _getAssociatedRecord ( Table $ table , string $ value ) : EntityInterface { $ primaryKey = $ table -> getPrimaryKey ( ) ; if ( ! is_string ( $ primaryKey ) ) { throw new UnsupportedPrimaryKeyException ( ) ; } // try to fetch with trashed if finder method exists, otherwise fallback to find all $ finderMethod = $ table -> hasBehavior ( 'Trash' ) ? 'withTrashed' : 'all' ; $ entity = $ table -> find ( $ finderMethod , [ 'conditions' => [ $ table -> aliasField ( $ primaryKey ) => $ value ] ] ) -> enableHydration ( true ) -> firstOrFail ( ) ; Assert :: isInstanceOf ( $ entity , EntityInterface :: class ) ; return $ entity ; }
Retrieve and return associated record Entity, by primary key value.
If the record has been trashed - query will return NULL.

@param \Cake\ORM\Table $table Table instance
@param string $value Primary key value
@return \Cake\Datasource\EntityInterface
Retrieve and return associated record Entity by primary key value . If the record has been trashed - query will return NULL .