V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
no13bus
V2EX  ›  问与答

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

  •  
  •   no13bus · 2014-03-06 21:42:03 +08:00 · 2313 次点击
    这是一个创建于 3710 天前的主题,其中的信息可能已经有所发展或是发生改变。
    下面是代码
    .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'这几个字段信息都没出来。请问是视图模型的字段设置的不对吗?
    2 条回复    1970-01-01 08:00:00 +08:00
    zsdsz
        1
    zsdsz  
       2014-03-06 21:52:43 +08:00 via iPhone
    Getlastsql看看
    no13bus
        2
    no13bus  
    OP
       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的字段出不来呢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   927 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:03 · PVG 03:03 · LAX 12:03 · JFK 15:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.