/** * Processes a field of a relation model * @param string $name Name of the field * @param zibo\library\database\manipulation\expression\TableExpression $table Table expression for the field * @param boolean $inCondition Flag to see whether the provided expression is used in a condition or not * @return zibo\library\database\manipulation\expression\FieldExpression */ private function processRelationFieldExpression($name, TableExpression $table, $inCondition) { $tableName = $table->getName(); try { $field = $this->meta->getField($tableName); } catch (OrmException $e) { if (!isset($this->tables[$tableName])) { throw new OrmParseException('Table ' . $tableName . ' is not added to the query'); } return new FieldExpression($name, $this->tables[$tableName], $tableName . self::ALIAS_SEPARATOR . $name); } $isRelationField = $field instanceof RelationField; if ($isRelationField) { $this->addFieldJoin($field); } $relationModel = $this->meta->getRelationModel($tableName); $relationField = $relationModel->getMeta()->getField($name); if ($relationField->isLocalized()) { $table = $this->meta->getRelationLocalizedTable($tableName); if ($inCondition && $isRelationField) { $joinCondition = $this->createLocalizeCondition($this->meta->getRelationTable($tableName), $table); $join = new JoinExpression(JoinExpression::TYPE_LEFT, $table, $joinCondition); $this->addConditionJoin($join); } } else { $table = new TableExpression($relationModel->getName(), $tableName); } return new FieldExpression($name, $table, $tableName . self::ALIAS_SEPARATOR . $name); }