model中:
<?php
namespace Home\Model;
use Think\Model\RelationModel;
class UserModel extends RelationModel {
protected $_li
'Cars'=>array(
'mapping_type'=>HAS_MANY,
'class_name'=>'Cars',
'foreign_key'=>'uid',
'condition'=>'uid',
),
);
}
controller:
<?php
namespace Home\Controller;
use Think\Controller;
use Home\Model\UserModel;
class IndexController extends Controller {
public function index(){
$user = D('User');
$row = $user->relation(true)->select();
dump($row);
}
}
表结构关联是一个用户可以有多张银行卡,已确定表里肯定有数据。
执行结果:
array(3) {
[0] => array(5) {
["uid"] => string(1) "1"
["username"] => string(3) "aaa"
["password"] => string(6) "123456"
["did"] => string(1) "1"
["Cars"] => NULL
}
[1] => array(5) {
["uid"] => string(1) "2"
["username"] => string(3) "bbb"
["password"] => string(6) "123456"
["did"] => string(1) "1"
["Cars"] => NULL
}
[2] => array(5) {
["uid"] => string(1) "3"
["username"] => string(3) "ccc"
["password"] => string(6) "123456"
["did"] => string(1) "1"
["Cars"] => NULL
}
}
为什么cars里面总是空的!!!!!紧急求助!!!!
试了很多次,换表,换文件都不行,一样的结果,是官方bug么?还是我操作有误?????
最佳答案