D
D
des1roer2015-05-21 11:24:34
Yii
des1roer, 2015-05-21 11:24:34

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

I receive
07GYW.png
in the model I can depict
$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);

so I will give id which to display.
but how to display the names with indents and sort along the path
UPD
did this
public function primaryKey()
        {
                return 'id';
        }

the generator made it possible to create controllers and views.
but when I access the view I get

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

1 answer(s)
A
Alexey Likhachev, 2015-05-21
@Playbot

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 question

Ask a Question

731 491 924 answers to any question