【发布时间】:2018-06-30 19:08:21
【问题描述】:
我有一个评论表,如下所示:
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | | NULL | |
| parent_id | int(11) | NO | | 0 | |
| post_id | int(11) | NO | | NULL | |
| body | text | NO | | NULL | |
| date | datetime | NO | | NULL | |
| status | tinyint(1) | NO | | 0 | |
+-----------+--------------+------+-----+---------+----------------+
评论parent_id默认为0,如果评论被回答,则在parent_id列中插入父id。
并使用以下代码与用户表建立关系:
public function getPosts()
{
return $this->hasMany(Post::className(), ['category_id' => 'id']);
}
如何显示嵌套?
【问题讨论】:
-
层次结构的最大级别是多少,或者假设您正在使用邻接列表模型,需要多少自连接才能检索任何顶级评论的单个路径?跨度>
-
没有限制,awirete a comment,b replay to a,c replay to b and ...,我需要一个递归函数来显示所有评论。
标签: activerecord yii2