本文整理汇总了PHP中Entity::getPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::getPrimaryKey方法的具体用法?PHP Entity::getPrimaryKey怎么用?PHP Entity::getPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity::getPrimaryKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processRecords
/**
* @param Entity $entity
* @param array $with
* @param $records
* @param $readOnly
*
* @return array
*/
public function processRecords(Entity $entity, array $with, $records, $readOnly)
{
$pkField = $entity->getPrimaryKey();
$objects = [];
$currentKey = null;
$object = null;
$recordsToProcess = [];
$relations = array_map([$entity, 'getRelation'], array_intersect($with, $entity->getRelationNames()));
foreach ($records as $record) {
//Extract columns that are relevant for the current metadata
$key = $record[$pkField];
if ($currentKey !== $key) {
if ($object !== null) {
//Process and save the previous object
$this->processRelated($entity, $object, $readOnly, $recordsToProcess, $relations, $with);
$recordsToProcess = [];
$objects[$currentKey] = $object;
}
$currentKey = $key;
$object = $this->createObject($entity, $record, $relations, $readOnly);
}
//Store the record to be processed for the related entities
$recordsToProcess[] = $record;
}
if ($object !== null) {
//Process and save the last object
$this->processRelated($entity, $object, $readOnly, $recordsToProcess, $relations, $with);
$objects[$key] = $object;
}
return $objects;
}
示例2: generateIndexes
private function generateIndexes(Entity $entity)
{
$indexes = array("\tPRIMARY KEY (`{$entity->getPrimaryKey()->getName()}`)");
foreach ($entity->getFinders() as $finder) {
$indexes[] = "\t" . $finder->getIndexDefinition();
}
return $indexes;
}
示例3: beforeSave
/**
* 注册entity
*/
protected function beforeSave()
{
if (!$this->entityId) {
$entity = new Entity();
$entity->type = lcfirst(get_class($this));
if ($entity->save()) {
$this->entityId = $entity->getPrimaryKey();
$this->_entity = $entity;
}
}
return parent::beforeSave();
}
示例4: load
/**
* @param Entity $entity
* @param $tableName
*/
public function load($entity, $tableName)
{
$primaryKey = $entity->getPrimaryKey();
$primaryKeyName = $entity->getPrimaryKeyName();
$criteria = array($primaryKeyName => $primaryKey);
$where = $this->buildWhereClause($criteria);
$sqlQuery = "SELECT * FROM " . $tableName . " WHERE " . $where;
$stm = $this->database->prepare($sqlQuery);
// Bind the where values
$parameterIndex = 1;
foreach ($criteria as $fieldName => &$value) {
$stm->bindParam($parameterIndex, $value);
$parameterIndex++;
}
$stm->execute();
if ($stm->rowCount() > 0) {
$row = $stm->fetch(PDO::FETCH_OBJ);
$entity->init($row);
$primaryKeyName = $entity->getPrimaryKeyName();
$entity->setPrimaryKey($entity->object->{$primaryKeyName});
}
}
示例5: getEntityByLastValueOfTabela
public static function getEntityByLastValueOfTabela(Entity $objeto)
{
$primaryKey = $objeto->getPrimaryKey();
$tabela = $objeto->getTableName();
$sql = "select * from {$tabela} order by {$primaryKey} desc limit 1";
$rs = self::returnDescription($sql, $objeto);
return $rs;
}
示例6: generateRemove
private function generateRemove(Entity $entity)
{
$pk = $entity->getPrimaryKey()->getName();
return "\tpublic function remove(\${$pk}) {\n" . "\t\t\$this->findByPrimaryKey(\${$pk});\n" . "\t\t\$this->db->updateQuery(\"DELETE FROM \".self::TABLE.\" WHERE {$pk}='\".addslashes(\${$pk}).\"'\");\n" . "\t\tparent::\$dbCache->resetEntity('{$entity->getName()}');\n" . "\t\tparent::\$dbCache->resetSingle(\"{$entity->getName()}\", \${$pk});\n" . "\t}\n\n";
}