public function get(Object $oObject, $aParams = array())
 {
     if (isset($this->aParams['ToModuleAlias'])) {
         Core::import('Modules.' . $this->aParams['ToModuleAlias']);
     }
     $oMapper = Manager::getInstance()->getMapper($this->aParams['ToMapperAlias']);
     $aContainer = $oMapper->getContainer();
     $sTable = $aContainer['TableName'];
     $sClassName = $aContainer['Object'];
     $oQuery = new DbFetcher($sTable, 'a');
     $oQuery->addJoinTable($this->aParams['TableName'], 'b', 'LEFT JOIN', 'a.id = b.' . $this->aParams['Field']);
     $oQuery->addSelectField('a.*');
     // Условия выборки
     $oCriteria = new CriteriaGroup('AND');
     $oCriteria->addElement(new CriteriaElement($this->aParams['Field2'], '=', (int) $oObject->getId()));
     $oQuery->addCriteria($oCriteria->renderWhere());
     if (isset($this->aParams['Order'])) {
         foreach ($this->aParams['Order'] as $k => $dir) {
             $oQuery->addOrder($k, $dir);
         }
     } else {
         $oQuery->addOrder('Pos', 'ASC');
     }
     $oResult = new ObjectsCollection($oQuery);
     $aResult = $oQuery->fetchAll();
     foreach ($aResult as $itm) {
         $oResult->add(new $sClassName($this->convRealFieldToFields($itm, '', $aContainer)));
     }
     return $oResult;
 }
 /**
  *
  * @param <type> $aParams
  * @return ObjectsCollection
  */
 public function find($aParams = array())
 {
     $paramsDefault = $this->scopeActive ? $this->scopeActive : $this->defaultScope();
     $aParams = ArrayHelper::merge($paramsDefault, $aParams);
     $this->scopeActive = false;
     $sClassName = $this->sModelAlias;
     $oQuery = new DbFetcher($this->tableName(), $sClassName, $this->getDbConnectionAlias());
     // Eager fetching
     if (isset($aParams['With'])) {
         if (is_string($aParams['With'])) {
             $aParams['With'] = array($aParams['With']);
         }
     }
     foreach ($this->oFields as $alias => $field) {
         if ($field->getType() != 'Object' && $field->getField()) {
             $oQuery->addSelectField($sClassName . '.' . $field->getField(), $field->getField());
         }
     }
     // Условия выборки
     if (isset($aParams['Criteria']) && is_object($aParams['Criteria'])) {
         $oQuery->addCriteria($aParams['Criteria']->renderWhere());
     }
     if (isset($aParams['Criteria']) && is_array($aParams['Criteria']) && count($aParams['Criteria']) > 0) {
         $oCriteria = new CriteriaGroup('AND');
         foreach ($aParams['Criteria'] as $k => $itm) {
             if (is_object($itm)) {
                 $oCriteria->addElement($itm);
             } else {
                 if (is_array($itm)) {
                     $oCriteria->addElement(new CriteriaElement($k, $itm['Type'], $itm['Value']));
                 } else {
                     $oCriteria->addElement(new CriteriaElement($k, '=', $itm));
                 }
             }
         }
         $oQuery->addCriteria($this->parseFindCriteria($oCriteria->renderWhere()));
     }
     if (isset($aParams['Criteria']) && is_string($aParams['Criteria'])) {
         $oQuery->addCriteria($this->parseFindCriteria($aParams['Criteria']));
     }
     // Лимит выборки
     if (isset($aParams['Limit']) && $aParams['Limit'] > 0) {
         $oQuery->setLimit($aParams['Limit']);
     }
     // Смещение выборки
     if (isset($aParams['Offset'])) {
         $oQuery->setOffset($aParams['Offset']);
     }
     // Сортировка
     if (isset($aParams['Order']) && is_array($aParams['Order']) && count($aParams['Order']) > 0) {
         foreach ($aParams['Order'] as $k => $itm) {
             $oQuery->addOrder($this->parseFindCriteria($k), $itm);
             //$oQuery->addOrder($k, $itm);
         }
     }
     if (isset($aParams['Group']) && is_array($aParams['Group']) && count($aParams['Group']) > 0) {
         foreach ($aParams['Group'] as $k => $itm) {
             $oQuery->addGroup($itm);
         }
     }
     if (isset($aParams['With']) && is_array($aParams['With']) && count($aParams['With'])) {
         foreach ($aParams['With'] as $k => $rel) {
             $oRelation = false;
             $aLocalParams = array();
             if (is_array($rel)) {
                 $oRelation = $this->oRelations->get($k);
                 $aLocalParams = $rel;
             } else {
                 if (is_string($rel)) {
                     $oRelation = $this->oRelations->get($rel);
                 }
             }
             if ($oRelation) {
                 $oQuery = $oRelation->eagerFetching($oQuery, $this, $sClassName, $aParams, $aLocalParams);
             }
         }
     }
     $oResult = new ObjectsCollection($oQuery);
     $aResult = $oQuery->fetchAll();
     $classNameWithNamespaces = '\\ruxon\\modules\\' . $this->sModuleAlias . '\\models\\' . $sClassName;
     foreach ($aResult as $itm) {
         $oItem = class_exists($sClassName) ? new $sClassName($this->convRealFieldToFields($itm)) : new $classNameWithNamespaces($this->convRealFieldToFields($itm));
         if (isset($aParams['With']) && is_array($aParams['With']) && count($aParams['With'])) {
             $this->parseJoinFields($oItem, $itm, $aParams['With'], $sClassName . '_');
         }
         $oResult->add($oItem);
     }
     return $oResult;
 }