本文整理汇总了PHP中EntityManager::getHasOneDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::getHasOneDefinition方法的具体用法?PHP EntityManager::getHasOneDefinition怎么用?PHP EntityManager::getHasOneDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::getHasOneDefinition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _processJoin
/**
* Procesa el JOIN y agrega las clausulas y condiciones requeridas
*
* @param string $joinType
*/
private function _processJoin($joinType)
{
$sqlStatement = '';
foreach ($this->_joins[$joinType] as $joinRelations) {
$mainEntity = $this->_entities[$joinRelations[0]];
$joinEntity = $this->_entities[$joinRelations[1]];
$hasRelation = false;
if (EntityManager::existsHasMany($joinEntity, $mainEntity)) {
$relation = EntityManager::getHasManyDefinition($joinEntity, $mainEntity, true);
$hasRelation = true;
} else {
if (EntityManager::existsBelongsTo($joinEntity, $mainEntity)) {
$relation = EntityManager::getBelongsToDefinition($joinEntity, $mainEntity);
$hasRelation = true;
} else {
if (EntityManager::existsHasOne($joinEntity, $mainEntity)) {
$relation = EntityManager::getHasOneDefinition($joinEntity, $mainEntity);
$hasRelation = true;
}
}
}
if ($hasRelation == false) {
throw new ActiveRecordException('Las entidades "' . $mainEntity . '" y "' . $joinEntity . '" no tienen cardinalidad definida');
}
$joinSource = EntityManager::getCompleteSource($joinEntity);
$mainSource = EntityManager::getCompleteSource($relation['referencedEntity']);
switch ($joinType) {
case self::LEFT_JOIN:
case self::RIGHT_JOIN:
if ($joinType == self::LEFT_JOIN) {
$sqlStatement .= ' LEFT OUTER JOIN ';
} else {
$sqlStatement .= ' RIGHT OUTER JOIN ';
}
$sqlStatement .= $joinSource . ' ON ';
if (is_string($relation['fields'])) {
$sqlStatement .= $joinSource . '.' . $relation['fields'] . ' = ' . $mainSource . '.' . $relation['referencedFields'];
if ($joinType == self::LEFT_JOIN) {
$condition = $joinSource . '.' . $relation['fields'] . ' IS NULL';
} else {
$condition = $relation['referencedSource'] . '.' . $mainSource . ' IS NULL';
}
$this->_appendCondition($condition);
} else {
$j = 0;
$joinConditions = array();
$whereConditions = array();
foreach ($relation['fields'] as $relationField) {
$joinConditions[] = $joinSource . '.' . $relationField . ' = ' . $mainSource . '.' . $relation['referencedFields'][$j];
if ($joinType == self::LEFT_JOIN) {
$whereConditions[] = $joinSource . '.' . $relationField . ' IS NULL';
} else {
$whereConditions[] = $mainSource . '.' . $relation['referencedFields'][$j] . ' IS NULL';
}
$j++;
}
$sqlStatement .= join(' AND ', $joinConditions);
$this->_appendCondition(join(' AND ', $whereConditions));
}
break;
case self::INNER_JOIN:
$sqlStatement .= ' INNER JOIN ' . $joinSource . ' ON ';
if (is_string($relation['fields'])) {
$sqlStatement .= $joinSource . '.' . $relation['fields'] . ' = ' . $mainSource . '.' . $relation['referencedFields'];
} else {
$j = 0;
$joinConditions = array();
$whereConditions = array();
foreach ($relation['fields'] as $relationField) {
$joinConditions[] = $joinSource . '.' . $relationField . ' = ' . $mainSource . '.' . $relation['referencedFields'][$j];
$j++;
}
$sqlStatement .= join(' AND ', $joinConditions);
}
break;
case self::NATURAL_JOIN:
$sqlStatement .= ',' . $joinSource;
if (is_string($relation['fields'])) {
$condition = $joinSource . '.' . $relation['fields'] . ' = ' . $mainSource . '.' . $relation['referencedFields'];
} else {
$j = 0;
$joinConditions = array();
$whereConditions = array();
foreach ($relation['fields'] as $relationField) {
$joinConditions[] = $joinSource . '.' . $relationField . ' = ' . $mainSource . '.' . $relation['referencedFields'][$j];
$j++;
}
$condition = join(' AND ', $joinConditions);
}
$this->_appendCondition($condition);
break;
case self::FULL_JOIN:
$sqlStatement .= ' FULL OUTER JOIN ' . $joinSource . ' ON ';
if (is_string($relation['fields'])) {
$sqlStatement .= $joinSource . '.' . $relation['fields'] . ' = ' . $mainSource . '.' . $relation['referencedFields'];
//.........这里部分代码省略.........