class UserModel extends RelationModel
{
protected $_link = array(
'Email' => array(
'class_name' => 'UserEmail',
'mapping_type' => HAS_MANY,
'foreign_key'=>'user_id',
'mapping_name'=>'user_email',
'mapping_fields' => '*',
),
'Education' => array(
'class_name' => 'UserEducation',
'mapping_type' => HAS_MANY,
'foreign_key'=>'user_id',
'mapping_name'=>'education',
'mapping_fields' => '*',
),
'Contact' => array(
'class_name' => 'UserContact',
'mapping_type' => HAS_MANY,
'foreign_key' => 'user_id',
'mapping_name' => 'user_contact',
'mapping_fields' => '*',
),
);
}
$obj = D('User');
//我只想关联 Email 表,relation方法的参数为 'Email'
$res = $obj->relation('Email')->where("user_id=1")->find();
//但是结果只查询了 User 表,Email 表和其他关系表都没有执行查询
// 只有relation 方法的参数为 true 时,才执行其他关系表的查询,
//但是这是执行所有的关系表查询,而我想要的是其中的几个关系表而不是全部
$res = $obj->relation(true)->where('user_id=1')->find(); //我不想查询所有的关系表-_-RelationModel 的 relation 参数为什么会失效,我需要怎么做捏? 最佳答案