src/flowcode/ceibo/EntityManager.php
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;
    }
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;
    }
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 ; }
Find by table relation.
@param type $entity
@param string $relationName
@param string $orderColumn
@param string $orderType
@return Collection
Find by table relation .