class SectionModel extends RelationModel{
protected $_li
'Category'=>array(
'mapping_type'=>self::HAS_MANY,
'class_name'=>'Category',
'mapping_name'=>'categorys',
'foreign_key'=>'sectionid'
),
下面是控制器中的代码
namespace Admin\Controller;
use Think\Controller;
use Admin\Model\SectionModel;
class SectionController extends CommonController{
function index(){
$User = D("Section");
$user = $User->relation(true)->find(1);
//$user = $User->relation(true)->Select();
dump($user);
}
使用find(1)就可以获取到Category表中的数据,如下:
array
'id' => string '1' (length=1)
'ti
'alias' => string '2015-12-24-15-36-53' (length=19)
'desc
'published' => string '0' (length=1)
'order' => string '0' (length=1)
'access' => string '0' (length=1)
'params' => string '' (length=0)
'categorys' =>
array
0 =>
array
'id' => string '1' (length=1)
'ti
使用select()就不能获取到Category表中的数据,如下:
array
0 =>
array
'id' => string '1' (length=1)
'ti
'alias' => string '2015-12-24-15-36-53' (length=19)
'desc
'published' => string '0' (length=1)
'order' => string '0' (length=1)
'access' => string '0' (length=1)
'params' => string '' (length=0)
'categorys' =>
array
0 =>
array
...
1 =>
到底是啥原因呢?
最佳答案