我有一个类似博客系统的东西。每个条目都可以有评论。每个评论都是由用户创建的。
我目前正在控制器上的“查看”操作中使用读取功能来检索所有数据。
模型之间的关系已经创建(belongTo、hasMany ...等)
当调用入口视图时,我得到如下信息:
['Entry'] => Array
(
[id] => 1
[body] => 'xxxxxx'
[...] => ...
)
[Comment] => Array
(
[0] => Array
(
[id] => 1
[user_id] => 1
[body] => This is an example of a comment guys!
[created] => 0000-00-00 00:00:00
)
[1] => Array
(
[id] => 2
[user_id] => 1
[body] => This is the 2nd comment!!!
[created] => 0000-00-00 00:00:00
)
)
有没有办法通过读取功能来检索评论的“递归”数据,例如与 user_id 相关的用户数据?(为了得到他们的名字等)
我期待这样的事情:
['Entry'] => Array
(
[id] => 1
[body] => xxxxxx
[...] => ...
)
[Comment] => Array
(
[0] => Array
(
[Comment] => Array
(
[id] => 1
[user_id] => 1
[body] => This is an example of a comment guys!
[created] => 0000-00-00 00:00:00
)
[User] => Array
(
[id] => 1
[username] => myusername
[created] => 0000-00-00 00:00:00
)
)
[1] => Array
(
[Comment] => Array
(
[id] => 1
[user_id] => 2
[body] => fasdfasfaT
[created] => 0000-00-00 00:00:00
)
[User] => Array
(
[id] => 2
[username] => myusername2
[created] => 0000-00-00 00:00:00
)
)
)
谢谢。