0
你好我想從HasMany中的多個表中選擇數據,但它不工作。這裏是我的代碼HasMany Multiple選擇不工作Cakephp
class UserInfo extends AppModel
{
public $useTable = 'user_info';
public $primaryKey = 'user_id';
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'type' => 'RIGHT',
'fields' => array('User.user_id','User.email','User.active')
)
);
public $hasMany = array(
'UserCategory' => array(
'className' => 'UserCategory',
'foreignKey' => 'user_id',
'dependent' => true,
'conditions' => array('user_id = UserCategory.user_id')
//'order' => 'UserCategory. DESC'
)
);
public function getUserDetails($user_id){
$this->Behaviors->attach('Containable');
return $this->find('all', array(
'conditions' => array(
'UserInfo.user_id' => $user_id
),
'contain' => array(
'User', 'UserCategory.Category',
)
));
}
如果我嘗試從有它user_id
這樣
public $hasMany = array(
'UserCategory' => array(
'className' => 'UserCategory',
'foreignKey' => 'user_id',
'dependent' => true,
'conditions' => array('user_id = UserCategory.user_id')
//'order' => 'UserCategory. DESC'
),
'Skill' => array(
'className' => 'Skill',
'foreignKey' => 'user_id',
'dependent' => true
)
);
它不取另一個表中提取數據。當我運行SQL轉儲。它根本不運行查詢。所以,含義,我無法從技能表
再次感謝您 – hellosheikh