
thinkphp关联模型的时候sql语句有问题
查询出来的数据是空的。而且sql语句中的条件也为空<?phpnamespaceHome\Model;useThink\Model\RelationModel;classU...
查询出来的数据是空的。而且sql语句中的条件也为空
<?php
namespace Home\Model;
use Think\Model\RelationModel;
class UserModel extends RelationModel{
//联表
protected $_link = array(
'talk' =>array(
'mapping_type' =>self::HAS_MANY ,
'foreign_key' =>'userID',
),
);
}
<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller {
public function a(){
$user = D('user');
$data = $user->relation(true)->select();
dump($data);
}
//输出
array (size=4)
'userid' => string '1' (length=1)
'username' => string '123' (length=3)
'userpassword' => string '123' (length=3)
'talk' =>
array (size=0)
empty 展开
<?php
namespace Home\Model;
use Think\Model\RelationModel;
class UserModel extends RelationModel{
//联表
protected $_link = array(
'talk' =>array(
'mapping_type' =>self::HAS_MANY ,
'foreign_key' =>'userID',
),
);
}
<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller {
public function a(){
$user = D('user');
$data = $user->relation(true)->select();
dump($data);
}
//输出
array (size=4)
'userid' => string '1' (length=1)
'username' => string '123' (length=3)
'userpassword' => string '123' (length=3)
'talk' =>
array (size=0)
empty 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询