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
333594
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;
    }
848572
public function primaryWhere(Entity $entity, $data, $table)
    {
        $primaryKeys = $entity->getRepository()->getCache()->getTablePrimaryKeys($table);

        if (strpos($table, '_i18n')) {
            $primaryKeys = ['id', 'language_id'];
        } elseif (strpos($table, '_p17n')) {
            $primaryKeys = ['id', 'user_group_id'];
        }

        foreach ($primaryKeys as $primaryKey) {
            $this->where('`' . $primaryKey . '`', $data[$primaryKey]);
        }
    }
987455
public function getTableInfo($table)
    {
        if (!$this->tableExists($table)) {
            return null;
        }
        
        $rtable = static::buildRealTableName($table, true);
        $key = 'db/tableinfo/' . $rtable;
        $data = static::getCache()->get($key);
        
        if (!$data) {
            $data = ['table_name' => $table];
            $data['fields'] = $this->getColumns($table);
            $pk = [];
            foreach ($data['fields'] as $key => $val) {
                if($val['is_primary']) {
                    $pk[] = $key;
                }
            }
            $data['primary_key'] = $pk ? $pk[0] : null;
            
            static::getCache()->set($key, $data);
        }
        
        return $data;
    }
164169
public function get($key, $value = null)
    {
        return $this->queryBag->key($key, $value, true);
    }
1344530
public function getPrimaryKeyDDL(Table $table)
    {
        if ($table->hasPrimaryKey() && !$table->hasAutoIncrementPrimaryKey()) {
            return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
        }

        return '';
    }
295416
public function parseValue($value, array $variables = null): EntityID
    {
        $value = parent::parseValue($value);

        return $this->createEntityID($value);
    }
356804
public function getPrimarykey($table=null) 
    {
        if ($table) {
            return $this->getDb()->getPrimaryKey($table);
        } else {
            if (!isset($this->options['primary_key'])) {
                $pk = $this->getDb()->getPrimaryKey($this->getTableName());
                $this->options['primary_key'] = $pk;
            }
            
            return $this->options['primary_key'];
        }
    }
1219874
public function getPrimaryKey($table)
    {
        $query = $this->getUtilityQuery();
        $results = $this->getColumns($table, "`Key` = 'PRI'");
        return isset($results[0]['Field']) ? $results[0]['Field'] : null;
    }
122258
public function selectBy($field, $value, $table = null)
	{
		if(null === $table)
		{
			$table = $this->tableName();
		}
		return $this->where(array((false === $table ? '' : ($table . '.')) . $field=>$value))->select();
	}
264567
public function getPrimaryFields(Table $table)
    {
        return $table->getFields()->filter(function (Field $field) {
            return $field->isPrimaryKey();
        });
    }
1172248
protected function getSerializedPropertyValue($value)
    {
        return ($value instanceof QueueableEntityInterface)
            ? new ModelIdentifier(get_class($value), $value->getQueueableId()) : $value;
    }
60542
protected function whenPivotLoaded($table, $value, $default = null)
    {
        if (func_num_args() === 2)
            $default = new MissingValue;

        return $this->when(
            $this->pivot && ($this->pivot instanceof $table || $this->pivot->getTable() === $table),
            ...[$value, $default]
        );
    }
1131048
protected function _getForeignKey(Table $table, string $modelName) : string
    {
        foreach ($table->associations() as $association) {
            if ($modelName !== $association->className()) {
                continue;
            }

            $primaryKey = $association->getForeignKey();
            if (! is_string($primaryKey)) {
                throw new RuntimeException('Primary key must be a string');
            }

            return $primaryKey;
        }

        return '';
    }
1003700
protected function retrieveByPrimaryKey(array $primary_key_values) {
		/** @var DynamicEntity $entity */
		$entity = parent::retrieveByPrimaryKey($primary_key_values);
		if ($entity) {
			$entity->definition = $this->definition;
		}
		return $entity;
	}
983071
protected function whenPivotLoadedAs($accessor, $table, $value, $default = null)
    {
        if (func_num_args() === 3) {
            $default = new MissingValue;
        }

        return $this->when(
            $this->resource->$accessor &&
            ($this->resource->$accessor instanceof $table ||
            $this->resource->$accessor->getTable() === $table),
            ...[$value, $default]
        );
    }
418320
public function getColumnDataForObject($value) : Row
    {
        /** @var EmbeddedParentObjectMapping $embeddedDefinition */
        $embeddedDefinition = $this->getRelation()->getEmbeddedObjectMapper()->getMapping();
        $rowData            = $embeddedDefinition->persistObject(PersistenceContext::dummy(), $value);

        return $rowData;
    }
632041
public function firstOrFail()
    {
        $entity = $this->first();
        if (!$entity) {
            /** @var \Cake\ORM\Table $table */
            $table = $this->getRepository();
            throw new RecordNotFoundException(sprintf(
                'Record not found in table "%s"',
                $table->getTable()
            ));
        }

        return $entity;
    }