/** * Filter out all soft deleted records from a select query if $filterDeleted is true. * Only apply the filter if the field being filtered on is not part of the original query. * * @param \Titon\Event\Event $event * @param \Titon\Db\Query $query * @param string $finder * @return bool */ public function preFind(Event $event, Query $query, $finder) { $config = $this->allConfig(); if ($config['filterDeleted']) { $where = $query->getWhere(); if ($config['useFlag']) { if (!$where->hasParam($config['flagField'])) { $query->where($config['flagField'], false); } } else { if (!$where->hasParam($config['deleteField'])) { $query->where($config['deleteField'], null); } } } return true; }
public function testGetSetConditionsParams() { $query = new Query(Query::SELECT); $this->object->setConditions(function (Query $query) { $query->where('status', 1); }); $this->assertEquals([], $query->getWhere()->getParams()); $query->bindCallback($this->object->getConditions(), $this->object); $this->assertEquals([new Expr('status', '=', 1)], $query->getWhere()->getParams()); }
public function testResolveParamsCompoundQueries() { $query1 = new Query(Query::SELECT, $this->table); $query1->where('username', 'like', '%foo%'); $query2 = new Query(Query::SELECT, $this->table); $query2->where('username', 'like', '%bar%'); $query1->union($query2); $this->assertEquals([['%foo%', PDO::PARAM_STR], ['%bar%', PDO::PARAM_STR]], $this->object->resolveParams($query1)); }