| | 1 | = Преглед на сите дискусии за даден топик |
| | 2 | == Актери |
| | 3 | * Ненајавен корисник |
| | 4 | == Чекори |
| | 5 | * Навигира до соодветниот топик. |
| | 6 | * Се прикажуваат сите дискусии во рамки на тој топик. |
| | 7 | == SQL |
| | 8 | {{{ |
| | 9 | create or replace view v_discussion_thread |
| | 10 | as |
| | 11 | with recursive |
| | 12 | depth_table as |
| | 13 | (select parent_id, id, 0 as depth |
| | 14 | from discussion_thread |
| | 15 | UNION ALL |
| | 16 | select discuss.parent_id, dpth.id, dpth.depth + 1 |
| | 17 | from depth_table dpth |
| | 18 | join discussion_thread discuss |
| | 19 | on dpth.parent_id = discuss.id), |
| | 20 | tmp as (select id, max(depth) as depth |
| | 21 | from depth_table |
| | 22 | group by id) |
| | 23 | select d.id as id, t.user_id as user_id, d.depth as depth, d1.parent_id as parent_id, t.created_at as "created_at" |
| | 24 | from tmp d |
| | 25 | join depth_table d1 |
| | 26 | on d.id = d1.id and d1.depth = d.depth |
| | 27 | join thread t |
| | 28 | on t.id = d.id; |
| | 29 | }}} |