实现四个表的关联

#1 lainel

我实现了3个表的关联,用户表 与 问题表  通过 回答表实现了多对多的关联,但是问题选项表加不进来,应该怎么配置啊?在MODLE中怎么设置,请教。在线等!

2011-06-29 09:14:25

#2 lainel

怎么没有人理我?

2011-06-29 09:55:09

#3 anythink

你好快哦...

2011-06-29 09:55:44

#4 anythink

你3个表都关了,4个表也是同样道理吧- -

2011-06-29 09:56:00

#5 lainel

还有,要用分页函数的话,是不是一定要用findAll()?

2011-06-29 09:56:02

#6 lainel

回复 4 anythink


    我试了,好像不行!

2011-06-29 09:57:47

#7 lainel

Array
(
    [0] => Array
        (
            [uid] => 1
            [sinaid] => 1651154580
            [createtime] => 1309221415
            [lastlogintime] => 1309309259
            [answernum] => 0
            [degree] => 1
            [d_question] => Array
                (
                    [0] => Array
                        (
                            [qid] => 5
                            [content] => 情感什么时候你会有想哭的冲动
                            [createtime] => 1309242298
                            [tid] => 1
                            [uid] => 1
                            [degree] => 1
                        )

                    [1] => Array
                        (
                            [qid] => 6
                            [content] => 马上要毕业了,突然发现自己爱上同学怎么办?
                            [createtime] => 1309242373
                            [tid] => 1
                            [uid] => 1
                            [degree] => 1
                        )

                    [2] => Array
                        (
                            [qid] => 7
                            [content] => 很久不见的同学和你的头像都亮着,你们会说话吗?
                            [createtime] => 1309242447
                            [tid] => 1
                            [uid] => 1
                            [degree] => 1
                        )

2011-06-29 09:59:16

#8 lainel

回复 7 lainel


    我想按问题分页,可是只能按用户分页

2011-06-29 10:00:54

#9 anythink

从记录上看关联了1个表?

2011-06-29 10:00:55

#10 lainel

有个关系表啊!用户表和问题表 通过回答表 关联起来的

2011-06-29 10:02:41

#11 lainel

class d_reply extends spModel
{
        public $table="d_reply";
        public $pk="rid";
}
class d_user extends spModel
{
        public $table="d_user";
        public $pk="uid";
       
         var $linker = array(  
array(
                                'type' => 'manytomany',   // 多对多关联
                                'map' => 'd_question',    // 关联的标识
                                'midclass' => 'd_reply', // 关联的中间表
                                'mapkey' => 'uid',  // 关联的字段
                                'fclass' => 'd_question', // 对应表的数据类
                                'fkey' => 'qid', // 对应表的关联字段
                                'enabled' => true
                ),
     );
     
}


class d_question extends spModel
{
        public $table="d_question";
        public $pk="qid";
        var $linker = array(  
         array(
                                'type' => 'manytomany',   // 多对多关联
                                'map' => 'd_user',    // 关联的标识
                                'midclass' => 'd_reply', // 关联的中间表
                                'mapkey' => 'qid',  // 关联的字段
                                'fclass' => 'd_user', // 对应表的数据类
                                'fkey' => 'uid', // 对应表的关联字段
                                'enabled' => true
                ),
                /*
                array(  
             'type' => 'hasmany',   // 一对多关联  
             'map' => 'd_questionoption',    // 关联的标识  
             'mapkey' => 'qid',  
             'fclass' => 'd_questionoption',  
             'fkey' => 'qid',  
             'enabled' => true  
         ),
                 */
                 
                );
}

2011-06-29 10:03:39

#12 lainel

查询时我用的是:        $result1=$user->spPager($this->spArgs('page',1),2)->spLinker()->findAll();

2011-06-29 10:04:24

#13 lainel

jake兄,不在吗?帮忙看看啊!:'(急

2011-06-29 10:06:32

#14 anythink

那就关联啊,通过制定modul的 pk 来和其他表关联

2011-06-29 10:09:26

#15 lainel

得到的结果不是我想要的啊!哎

2011-06-29 10:18:19

#16 lainel

自己写吧!

2011-06-29 10:18:52

#17 jake

复合调用

http://www.speedphp.com/model-complex.html

2011-06-29 11:02:18