2012-04-19 68 views
-1

加入我有2個表
student_job_log - > ID,JOB_ID,student_id數據,created_dt
student_info - > ID,USER_ID,名字,姓氏
留在警予

我已在關係模型(studentJobLog)

public function relations() 
    { 
     // NOTE: you may need to adjust the relation name and the related 
     // class name for the relations automatically generated below. 
     return array(
     'student_info'=>array(self::BELONGS_TO,'StudentInfo','id','joinType'=>'LEFT JOIN', 
            'select'=>'first_name, last_name')), 


     ); 
    } 

我得到的錯誤在這 是什麼問題。 事情是錯誤的,我的關係,我不知道:(

我想從student_info PLZ的FIRST_NAME和LAST_NAME幫我... :(

+4

什麼錯誤?我們應該猜到的? – Jon 2012-04-19 10:11:58

+0

你好@喬恩請給我查詢(重lations)...我想從student_info表中創建first_name和last_name,並從student_job_log中創建created_dt – User1988 2012-04-19 10:16:05

+2

我不能那樣做。如果你有一個具有充分記錄的特定問題,我可以提供幫助。 – Jon 2012-04-19 10:18:09

回答

0

外鍵必須從你所映射的一個電流模式到StudentInfo

return array(
    'student_info'=>array(self::BELONGS_TO,'StudentInfo','student_id',), 
    ); 

現在使用它像

echo $job->student_info->first_name . ', ' . $job->student_info->last_name;