求助一下,ThinkPHP3.2里一个Model不能进行两次关联查询吗?

浏览:610 发布日期:2016/08/23 分类:求助交流 关键字: Model 关联查询 relation
我在一个Model里写了两个方法,两个均要进行relation操作

第一个没问题,通过D方法实例化后的对象里是有_link变量的

然而D方法实例化第二个表对象的时候,里面就没有_link了,会提示我没有relation方法

然后我尝试新建了一个Model,第二个表对象放进去关联查询,是可以的。。。

请问一下有没有多次查询的方法呢,百度谷歌好久没找到解决方法。。relationGet也不行<?php

namespace Home\Model;

use Think\Model\RelationModel;

class ClientModel extends RelationModel {
    // 映射字段
    // protected $_map = array (
    // 'signup-email' => 'email',
    // 'signup-name' => 'name',
    // 'signup-tel' => 'tel',
    // 'signup-id' => 'idCard'
    // );
    protected $_link = array (
            'CardType' => array (
                    'mapping_type' => self::HAS_ONE,
                    'class_name' => 'card_type',
                    'mapping_name' => 'card_type_id',
                    'foreign_key' => 'id'
            ),
            'CardDate' => array (
                    'mapping_type' => self::HAS_ONE,
                    'class_name' => 'card_time',
                    'mapping_name' => 'card_date_id',
                    'foreign_key' => 'id'
            ),
            'PointInfo' => array (
                    'mapping_type' => self::HAS_MANY,
                    'class_name' => 'point_type',
                    'mappint_name' => 'point_type_id',
                    'foreign_key' => 'id'
            )
    );
    function login($client, $data) {
        $where = array ();
        $where ['username'] = $data ['username'];
        $result = $client->relation ( true )->where ( $where )->find ();
        return $result;
    }
    function queryCurrentUserPoint($point, $data) {
        // echo var_dump ( $point );
        // die ();
        $where = array ();
        $where ['client_id'] = $data ['client_id'];
        $result = $point->where ( $where )->find (1);
        $result = $point->relationGet ( 'PointInfo' );
        echo var_dump ( $result );
        die ();
        return $result;
    }
}
?>
最佳答案
评论( 相关
后面还有条评论,点击查看>>