public function lookupRange(&$escapedField, &$rawValue, &$negate) { if (!is_array($rawValue) || count($rawValue) !== 2) { throw new \InvalidArgumentException("value for RANGE lookup must me array with two elements"); } $rawValue = Expr($this->db->quote($rawValue[0]) . ' AND ' . $this->db->quote($rawValue[1])); return 'BETWEEN %s'; }
public function testExpr() { $this->assertInstanceOf('\\Dja\\Db\\Model\\Expr', Expr('v')); }
public function testFilterIn2() { $q = UserModel::objects()->filter(['user_id__in' => Expr('SELECT user_id FROM "user"')]); $this->assertInstanceOf('\\Dja\\Db\\Model\\Model', $q->current()); }
/** * @param \Dja\Db\Model\Model $model * @return \Dja\Db\Model\Query\QuerySet */ public function getRelation(\Dja\Db\Model\Model $model) { /** @var \Dja\Db\Model\Model $relationClass */ $relationClass = $this->relationClass; /** @var \Dja\Db\Model\Model $throughClass */ $throughClass = $this->throughClass; if ($throughClass) { $in = $throughClass::objects()->filter([$this->self_field => $model->__get($this->self_field)])->valuesList($this->to_field, false); } else { $sql = sprintf('SELECT "%s" FROM "%s" WHERE "%s" = %d', $this->to_field, $this->db_table, $this->self_field, $model->__get($this->self_field)); //$in = $relationClass::objects()->setRawSql($sql)->valuesDict($this->to_field, $this->to_field); $in = Expr($sql); } if ($this->limit_choices_to) { $filter = $this->limit_choices_to; $filter[$this->to_field . '__in'] = $in; return $relationClass::objects()->relation($model, $this)->filter($filter); } else { return $relationClass::objects()->relation($model, $this)->filter([$this->to_field . '__in' => $in]); } }