no13bus
V2EX  ›  问与答

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

  •  
  •   no13bus · Mar 6, 2014 · 2785 views
    This topic created in 4450 days ago, the information mentioned may be changed or developed.
    下面是代码
    .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 replies    1970-01-01 08:00:00 +08:00
    zsdsz
        1
    zsdsz  
       Mar 6, 2014 via iPhone
    Getlastsql看看
    no13bus
        2
    no13bus  
    OP
       Mar 6, 2014
    @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的字段出不来呢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3309 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 11:46 · PVG 19:46 · LAX 04:46 · JFK 07:46
    ♥ Do have faith in what you're doing.