protected $_link = array(
/*
*关联模型'carmodel' 从属于'car' 表
*/
'car' => array(
'mapping_type' => self::BELONGS_TO,
'foreign_key' => 'car_name_id',//外键
'mapping_fields'=> 'carname',//需要显示的关联表的字段
'as_fields' => 'carname',//同级显示字段的名称
),
/*
*关联模型'carmodel' 一对多 'sellgoods' 表
*/
'sellgoods' => array(
'mapping_type' => self::HAS_MANY,
'mapping_name' => 'sellname',
'foreign_key' => 'sell_goods_id',
'relation_deep' => 'true'
)
); $ee = D('carmodel');
$eee = $ee->Relation('true')->select();
var_dump($eee);controller中的代码 最佳答案