Extract specific entity

@param integer $primaryKey

@return null|ActiveRecordInterface
431602
protected function _get($primaryKey)
    {
        $this->hydrateModel($primaryKey);

        return ($this->getModel() instanceof ActiveRecordInterface) ? $this->getModel() : NULL;
    }
1362252
public function extract($entity)
    {
        $metadata = $this->getMetadata();
        $collection = [];
        
        foreach ($metadata->getSQLNames() as $sqlName) {
            $propertyName = $metadata->getName($sqlName, Metadata::CAMILIZED);
            $propertyValue = $this->getReflection()->getProperty($propertyName)->getValue($entity);
            $propertyValue = $propertyValue !== null
                ? $metadata->toPlatform($metadata->getName($sqlName), $propertyValue) : null;
            $collection[$sqlName] = $propertyValue;
        }
        
        return $collection;
    }
995240
public function find( $primaryKeys )
    {
        if ( is_array( $primaryKeys ) )
        {
            $primaryKeys = reset( $primaryKeys );
        }

        $rootId = ( (int) $primaryKeys ) ?: null;

        return $this->createStructure( array(
            'rootId'    => $rootId,
            'extra'     => $this->getExtraMapper()
                                ->findByRoot( $rootId ),
            'rules'     => $this->getRuleMapper()
                                ->findAllByRoot(
                                    $rootId,
                                    $this->getRuleOrder()
                                ),
        ) );
    }
932995
protected function _getIds(array $ids, $primaryKey = self::PRIMARY_KEY)
    {
        $return = [];
        foreach ($ids as $id => $value) {
            if (is_array($value) && is_int($id) && (int) $value[$primaryKey] === 1) {
                $return[$id] = $id;
            }
        }

        return $return;
    }
6871
protected function getGenericPrimaryKey(array $primaryKey)
    {
        $genericPrimaryKey = new PrimaryKey($primaryKey[0]['name']);

        foreach ($primaryKey as $primaryKeyColumn) {
            $genericPrimaryKey->addColumnName($primaryKeyColumn['column_name']);
        }

        return $genericPrimaryKey;
    }
1166508
public static function getPrimaryKey()
    {
        $attribute = 'primary-key';

        // retrieve value from class setting definition
        if (!static::hasClassAttribute($attribute)) {
            $key = null;
            $schema = static::getSchema();

            foreach ($schema as $field => $aspects) {
                if ($aspects['Key'] == 'PRI') {
                    $key = $field;
                    break;
                }
            }

            static::setClassAttribute($attribute, $key);
        }

        return static::getClassAttribute($attribute);
    }
749125
public function findPrimaries(array $primaryValues, array $associate = [])
    {
        $reflection = Entity\Reflection::load($this->getEntityName());

        if (!$reflection->hasPrimary()) {
            throw new Exception\RepositoryException(
                "Method can not be used because entity " . $this->getEntityName()
                . " has no primary property defined!"
            );
        }

        if (empty($primaryValues)) {
            throw new Exception\RepositoryException(
                "Values can not be empty!"
            );
        }

        try {

            return $this->query()
                ->select()
                ->setFilter(
                    [
                        $reflection->getPrimaryProperty()->getName() => [
                            Filter::EQUAL => $primaryValues
                        ]
                    ]
                )
                ->associate($associate)
                ->run($this->connection);
        } catch (Exception\QueryException $e) {
            throw new Exception\RepositoryException($e->getMessage());
        }
    }
908549
public function extract()
    {
        $array_recurse = function ($val) use (&$array_recurse) {
            if (is_scalar($val)) {
                return $val;
            }

            if (is_array($val)) {
                if (is_array(current($val)) || (is_object(current($val)) && current($val) instanceof FlexibleEntityInterface)) {
                    return array_map($array_recurse, $val);
                } else {
                    return $val;
                }
            }

            if (is_object($val) && $val instanceof FlexibleEntityInterface) {
                return $val->extract();
            }

            return $val;
        };


        return array_map($array_recurse, array_merge($this->container, $this->getCustomFields()));
    }
903561
public function getPrimaryKeyName()
    {
        if ($this->primaryKey == null) {
            $model = $this->getModel();
            $this->primaryKey = $model->getPrimaryKeyName();
        }
        return $this->primaryKey;
    }
1245839
protected function key($data = null)
    {
        if (is_null($data)) {
            $data = $this->getPK();
            //
            if (Table::count($data) > 1) {
                throw new ManyPrimaryKeysException();
            } elseif (Table::count($data) == 0) {
                throw new PrimaryKeyNotFoundException(static::$table);
            }
            //
            $this->_keyName = $data[0]['Column_name'];
            $this->_key['name'] = $data[0]['Column_name'];
        } else {
            $this->_keyName = $data['key'];
            $this->_key['name'] = $data['key'];
        }
    }
717697
public function getPrimary() {
        foreach ($this->_fields as $key => $field) {
            if ($field->primary == true) {
                $this->_primary = $key;
                break;
            }
        }
    }
820116
public function getPrimaryKey(){
		$table = $this->getTable();
		if(!$table)
			return null;
		$key = null;
		$cached = $this->connection->getCache()->fetch($table . '_primaryKey');

		if($cached === null){
			try{
				$key = $this->connection->getDriver()
					->getPrimaryKey($table, isset($this->resultSet) ? $this->resultSet : null);
			} catch(NeevoException $e){
				return null;
			}
			$this->connection->getCache()->store($table . '_primaryKey', $key);
			return $key === '' ? null : $key;
		}
		return $cached === '' ? null : $cached;
	}
476305
public function findOne($primary)
    {
        $item = $this->getRegistry()->get($primary);
        if (!$item) {
            $all = $this->getRegistry()->get("all");
            if ($all) {
                $item = $all[$primary];
            }
            if (!$item) {
                $params['where'][] = ["`{$this->getTable()}`.`{$this->getPrimaryKey()}` = ?", $primary];
                $item = $this->findOneByParams($params);
                if ($item) {
                    $this->getRegistry()->set($primary, $item);
                }

                return $item;
            }
        }

        return $item;
    }
424214
public function comparePrimaryKeys(PrimaryKey $oldPrimaryKey, PrimaryKey $newPrimaryKey)
    {
        return ($oldPrimaryKey->getName() !== $newPrimaryKey->getName())
            || ($oldPrimaryKey->getColumnNames() !== $newPrimaryKey->getColumnNames());
    }
123302
public static function convertPrimaryKeyArrayToString(array $primaryKey) : string
    {
        $wrappedElements = \iRAP\CoreLibs\ArrayLib::wrapElements($primaryKey, '`');
        $csv = implode(',', $wrappedElements);
        return $csv;
    }
1264499
public function extract() {
        $pkValues = array();
        // Lose the parentheses, they mean nothing to us (more importantly, "((key = value))" fails)
        // @fixme A string primary key containing a "(" will not be returned.
        $where = str_replace(array('(', ')'), '', $this->_where);
        foreach ($this->_pkColumns as $pk) {
            $regexp = '/(?:`?' . preg_quote($this->_tableName) . '`?\.|\s|^){1}`?(?:' .
                preg_quote($pk) .
                ')`?\s?=\s?(?:(?P<q>[\'"])(?P<value>(?:(?!\k<q>).)*)\k<q>|(?P<rest>\w*))/';
            if (!preg_match($regexp, $where, $matches)) {
                continue;
            }
            // Note: backreference "rest" is there to catch unquoted
            // values. (id = 100 instead of id = "100")
            $value = $matches['value'];
            if (!empty($matches['rest'])) {
                $value = $matches['rest'];
            }
            $pkValues[$pk] = $value;
        }
        return $pkValues;
    }
260913
protected function getPrimaryKeyColumn($entityMetadata)
    {
        $primaryKey = 'id';
        $incrementing = true;

        foreach ($entityMetadata['table']['columns'] as $column) {
            if ($column['primary']) {
                return $column;
            }
        }
    }