在 cakephp 中显示另一个表中的属性


Showing the attribute from another table in cakephp

我有两个表Shift和ShiftSession。这种关系就像班次有很多班次,班次属于班次。

我像这样定义移位会话模型的关系。

var $name = 'ShiftSession';                    
var $belongsTo = array(        
      'Shift' => array(            
         'className'    => 'Shift',            
         'foreignKey'    => 'ShiftID'
       )    
    );  

问题是我想在班次会话表中显示从班次表而不是 shiftID 的班次名称。

你必须尝试:

$this->ShiftSession->find('all');

这将从表中返回相应的数据Shift