/**
  * @return ISqlSelectQuery
  */
 private function makeSqlSelectQuery(EntityQuery $query)
 {
     $query = $query->toSelectQuery();
     $joinMethod = SqlJoinMethod::INNER;
     $childrenTable = $this->getChildren()->getPhysicalSchema()->getTable();
     $proxyTable = $this->mtm->getProxy()->getPhysicalSchema()->getTable();
     $condition = Expression::andChain();
     $srcSqlFields = $this->getChildren()->getLogicalSchema()->getIdentifier()->getFields();
     $dstSqlFields = $this->mtm->getEncapsulantProxyProperty()->getFields();
     foreach ($srcSqlFields as $k => $v) {
         $condition->add(Expression::eq(new SqlColumn($srcSqlFields[$k], $childrenTable), new SqlColumn($dstSqlFields[$k], $proxyTable)));
     }
     $query->join(new SqlConditionalJoin(new SelectQuerySource(new SqlIdentifier($proxyTable)), new SqlJoinMethod($joinMethod), $condition));
     $columnName = $this->mtm->getContainerProxyProperty()->getField();
     $query->andWhere(Expression::eq(new SqlColumn($columnName, $this->mtm->getProxy()->getPhysicalSchema()->getTable()), new SqlValue($this->getParentObject()->_getId())));
     return $query;
 }
 /**
  * @return void
  */
 private function join(OrmProperty $property, AssociationPropertyType $type, EntityQueryBuilder $builder, SelectQuerySource $source)
 {
     $joinMethod = $type->getAssociationMultiplicity()->is(AssociationMultiplicity::EXACTLY_ONE) ? SqlJoinMethod::INNER : SqlJoinMethod::LEFT;
     $condition = Expression::andChain();
     $srcSqlFields = $property->getFields();
     $dstSqlFields = $builder->entity->getLogicalSchema()->getIdentifier()->getFields();
     foreach ($srcSqlFields as $k => $v) {
         $condition->add(Expression::eq(new SqlColumn($srcSqlFields[$k], $this->alias), new SqlColumn($dstSqlFields[$k], $builder->alias)));
     }
     $source->join(new SqlConditionalJoin(new SelectQuerySource(new AliasedSqlValueExpression(new SqlIdentifier($builder->table), $builder->alias)), new SqlJoinMethod($joinMethod), $condition));
 }