Пример #1
0
 public function testBuildFromMapping_withRelationsLazyTrue_ok()
 {
     $ovni = new Weapon();
     $mapping = simplexml_load_file($this->mappingFilePath);
     $mapper = $this->object->buildFromClassName($mapping, get_class($ovni));
     $this->assertEquals(get_class($ovni), $mapper->getClass());
     $relations = $mapper->getRelations();
     $this->assertEquals(true, $relations["Ovnis"]->isLazy());
 }
Пример #2
0
 /**
  * Find by table relation.
  * @param type $entity
  * @param string $relationName
  * @param string $orderColumn
  * @param string $orderType
  * @return Collection
  */
 public function findRelation($entity, $relationName, $orderColumn = null, $orderType = null)
 {
     $this->load();
     $mapper = MapperBuilder::buildFromClassName($this->mapping, get_class($entity));
     $relation = $mapper->getRelation($relationName);
     $relationMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());
     $selectQuery = "SELECT tmain.* FROM `" . $relationMapper->getTable() . "` tmain ";
     $joinQuery = QueryBuilder::buildJoinRelationQuery($relation, "tmain", "j1");
     $whereQuery = "WHERE j1." . $relation->getLocalColumn() . " = '" . $entity->getId() . "'";
     $orderQuery = "";
     if (!is_null($orderColumn)) {
         $orderQuery .= "ORDER BY {$orderColumn} ";
         if (!is_null($orderType)) {
             $orderQuery .= "{$orderType}";
         } else {
             $orderQuery .= "ASC";
         }
     }
     $query = $selectQuery . $joinQuery . $whereQuery . $orderQuery;
     $queryResult = $this->getDataSource()->query($query);
     if ($queryResult) {
         $collection = new Collection($relationMapper->getClass(), $queryResult, $relationMapper);
     } else {
         $collection = new Collection($relationMapper->getClass(), array(), $relationMapper);
     }
     return $collection;
 }