Exemplo n.º 1
0
 public function __construct(Connection $connection, Model $model)
 {
     $this->model = $model;
     $this->connection = $connection;
     $compiler = $connection->compiler();
     $query = new Select($compiler, $model->getTable());
     $whereCondition = new WhereCondition($this, $query);
     parent::__construct($compiler, $query, $whereCondition);
 }
Exemplo n.º 2
0
 /**
  * @param   array|null  $ids        (optional)
  * @param   array       $columns    (optional)
  *
  * @return  array
  */
 public function findMany(array $ids = null, array $columns = array())
 {
     if ($ids !== null && !empty($ids)) {
         $this->query->where($this->model->getPrimaryKey())->in($ids);
     }
     return $this->all($columns);
 }
Exemplo n.º 3
0
 /**
  * @param   array   &$columns   (optional)
  *
  * @return  \Opis\Database\ResultSet
  */
 protected function query(array &$columns = array())
 {
     $pk = $this->model->getPrimaryKey();
     if (!$this->query->isLocked() && !empty($columns)) {
         $columns[] = $pk;
     }
     return $this->connection->query((string) $this->query->select($columns), $this->query->getCompiler()->getParams());
 }
Exemplo n.º 4
0
 protected function prepareResults(Model $model, array &$results)
 {
     if (!empty($results) && !empty($this->with)) {
         $pk = $model->getPrimaryKey();
         $attr = $this->getWithAttributes();
         $ids = array();
         foreach ($results as $result) {
             $ids[] = $result->{$pk};
         }
         foreach ($attr['with'] as $with => $callback) {
             if (!method_exists($model, $with)) {
                 continue;
             }
             $loader = $model->{$with}()->getLazyLoader(array('ids' => $ids, 'callback' => $callback, 'with' => $attr['extra'][$with], 'immediate' => $this->immediate));
             if ($loader === null) {
                 continue;
             }
             foreach ($results as $result) {
                 $result->setLazyLoader($with, $loader);
             }
         }
     }
 }