thinkphp 里面的视图模型我用来实现多表联合查询,类似 V2EX 的用户和节点,帖子的关系。想查找当前的节点下面每个帖子的相关信息。结果有几个字段没出来。

2014-03-06 21:42:03 +08:00
 no13bus
下面是代码
https://gist.github.com/9389800.git

下面是得到数据的程序段。
$topics = D('TopicView')->order('last_touched desc,created desc,last_replied_time desc,id desc')->select();
$this->topics = $topics;

结果'username','nickname','avatar','uid','reputation'这几个字段信息都没出来。请问是视图模型的字段设置的不对吗?
2335 次点击
所在节点    问与答
2 条回复
zsdsz
2014-03-06 21:52:43 +08:00
Getlastsql看看
no13bus
2014-03-06 21:57:16 +08:00
@zsdsz SELECT topic.id AS id,topic.title AS title,topic.content AS content,topic.last_replied_by AS last_replied_by,topic.last_touched AS last_touched,topic.created AS created,last_replied_user.username AS last_replied_username,node.name AS nodename,node.slug AS nodeslug FROM mn_topic topic JOIN mn_user last_replied_user ON topic.last_replied_by=last_replied_user.uid JOIN mn_node node ON topic.node_id=node.id ORDER BY topic.last_touched desc,topic.created desc,last_replied_time desc,topic.id desc
确实没有username字段。我想说因为帖子有最后回复的人 还有发帖人。这2种人都是属于user表的。所以我在视图模型里面用了2次user表,但是最后的用_as修改了显示名称呀。为什么前面的那个user的字段出不来呢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/103177

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX