Answer the question
In order to leave comments, you need to log in
Recursive query in yii in sort?
there is a postgres request
WITH RECURSIVE temp1 ( id,id_parent,name,PATH, LEVEL, myname ) AS (
SELECT T1.id,T1.id_parent, T1.name, CAST (T1.id AS VARCHAR (50)) as PATH, 1 ,
CAST (T1.name AS VARCHAR (255)) as myname
FROM t_department T1 WHERE T1.id_parent = 5 and t1.type::int = 1 and t1.hidden = 0
union
select T2.id, T2.id_parent, T2.name, CAST ( temp1.PATH ||'->'|| T2.id AS VARCHAR(50)) ,LEVEL + 1 ,
CAST ((repeat(' _ ', LEVEL+1)||T2.name) AS VARCHAR(255))
FROM t_department T2 INNER JOIN temp1 ON( temp1.id= T2.id_parent))
select * from temp1
ORDER BY PATH desc LIMIT 100
$dataReader = $connection->createCommand($sql)->query();
$rows = $dataReader->readAll();
for($i = 0, $cnt = count($rows); $i < $cnt; $i++) //формируем столбцы
{
$id[] = $rows[$i]['id'];
}
$criteria->addInCondition('id', $id);
public function primaryKey()
{
return 'id';
}
CException
Mymodel contains an invalid validation rule. The rule must have a name and include elements to check.
Answer the question
In order to leave comments, you need to log in
I usually make a view directly in the database for complex queries that quite often need to be performed, and then I work with this view as with a table, that is, I will make a model for it and immediately all sorting and filtering start working without hemorrhoids
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question