/** * @return SelectQuery **/ protected function joinHelperTable(SelectQuery $query) { $uc = $this->container; if (!$query->hasJoinedTable($uc->getHelperTable())) { $query->join($uc->getHelperTable(), Expression::eq(new DBField($uc->getParentTableIdField(), $uc->getDao()->getTable()), new DBField($uc->getChildIdField(), $uc->getHelperTable()))); } return $query->andWhere(Expression::eq(new DBField($uc->getParentIdField(), $uc->getHelperTable()), new DBValue($uc->getParentObject()->getId()))); }
private function joinProperties(SelectQuery $query, ProtoDAO $parentDao, $parentTable, $parentRequired, $prefix = null) { $proto = call_user_func([$parentDao->getObjectName(), 'proto']); foreach ($proto->getPropertyList() as $property) { if ($property instanceof LightMetaProperty && $property->getRelationId() == MetaRelation::ONE_TO_ONE && !$property->isGenericType() && (!$property->getFetchStrategyId() && $this->getFetchStrategy()->getId() == FetchStrategy::JOIN || $property->getFetchStrategyId() == FetchStrategy::JOIN)) { if (is_subclass_of($property->getClassName(), Enumeration::class) || is_subclass_of($property->getClassName(), Enum::class) || is_subclass_of($property->getClassName(), Registry::class)) { // field already added by makeSelectHead continue; } elseif ($property->isInner()) { $proto = call_user_func([$property->getClassName(), 'proto']); foreach ($proto->getPropertyList() as $innerProperty) { $query->get(new DBField($innerProperty->getColumnName(), $parentTable)); } continue; } $propertyDao = call_user_func([$property->getClassName(), 'dao']); // add's custom dao's injection possibility if (!$propertyDao instanceof ProtoDAO) { continue; } $tableAlias = $propertyDao->getJoinName($property->getColumnName(), $prefix); $fields = $propertyDao->getFields(); if (!$query->hasJoinedTable($tableAlias)) { $logic = Expression::eq(DBField::create($property->getColumnName(), $parentTable), DBField::create($propertyDao->getIdName(), $tableAlias)); if ($property->isRequired() && $parentRequired) { $query->join($propertyDao->getTable(), $logic, $tableAlias); } else { $query->leftJoin($propertyDao->getTable(), $logic, $tableAlias); } } foreach ($fields as $field) { $query->get(new DBField($field, $tableAlias), $propertyDao->getJoinPrefix($property->getColumnName(), $prefix) . $field); } $this->joinProperties($query, $propertyDao, $tableAlias, $property->isRequired() && $parentRequired, $propertyDao->getJoinPrefix($property->getColumnName(), $prefix)); } } }