2013-05-30 51 views
0

嗯,我沒有看到代碼和表的任何錯誤,但即時通訊顯示我需要的數據時遇到問題。Cakephp HasOne()表關係不工作

因爲已經創建並填充表,這裏就是我的了:

class Business extends AppModel 
    { 
     public $name = "Business"; 
     public $useTable = "businesses"; 

     public $hasOne = array(
     'user_profiles' => array(
      'className'  => 'profiles', 
      'foreignKey' => false, 
      'conditions' => array('Business.business_id = profiles.user_id') 
     )); 
    } 

我調試它在我的控制器的結果是這樣的:

array(
    (int) 0 => array(
     'Business' => array(
      'business_id' => '1', 
      'business_name' => 'sysnet admin', 
      'mac1' => '1f', 
      'mac2' => 'af', 
      'mac3' => '12', 
      'mac4' => 'aa', 
      'mac5' => '33', 
      'mac6' => 'ba', 
      'area_id' => '1', 
      'latitude' => '', 
      'longitude' => null, 
      'province_id' => null, 
      'max' => '20', 
      'upload' => '0', 
      'download' => '0', 
      'allow_bypass' => '1', 
      'bypass_pin' => '0000000', 
      'gate_way' => '192.168.88.1', 
      'trial' => '0', 
      'hasExpired' => '0', 
      'isRedirectEnabled' => '0', 
      'redirectLink' => 'www.google.com', 
      'group_admin_id' => '1', 
      'last_access_time' => '2013-05-23 09:15:37' 
     ) 
    ), 
    (int) 1 => array(
     'Business' => array(
      'business_id' => '89', 
      'business_name' => 'Panthera', 
      'mac1' => 'd4', 
      'mac2' => 'ca', 
      'mac3' => '6d', 
      'mac4' => '65', 
      'mac5' => '60', 
      'mac6' => '8b', 
      'area_id' => '1', 
      'latitude' => '14.5580', 
      'longitude' => '121.0183', 
      'province_id' => '1', 
      'max' => '20', 
      'upload' => '0', 
      'download' => '0', 
      'allow_bypass' => '1', 
      'bypass_pin' => 'X7veJ2p', 
      'gate_way' => '172.16.88.1', 
      'trial' => '0', 
      'hasExpired' => '0', 
      'isRedirectEnabled' => '0', 


      'redirectLink' => 'www.google.com', 
       'group_admin_id' => '2', 
       'last_access_time' => '2013-05-23 09:15:52' 
      ) 
     ), 
.... 
} 

什麼似乎是問題?我還需要用戶配置文件與其匹配的業務記錄一起顯示。請幫忙。我已經搜索了答案,但我編碼相同的行,所以我不知道問題所在。

回答

4

根據Cake約定,您並未創建關係。

public $hasOne = array(
    'user_profiles' => array(
     'className'  => 'profiles', 
     'foreignKey' => false, 
     'conditions' => array('Business.business_id = profiles.user_id') 
    )); 

VS

public $hasOne = array(
    'UserProfile' => array(
     'className'  => 'Profile', 
     'foreignKey' => false, 
     'conditions' => array('Business.business_id = Profile.user_id') 
    )); 
+0

我用蛋糕v3和兩個數組鍵爲「類名」的值是複數在我的情況,僅供參考。 – klaar

+0

這是幾年前,可能蛋糕1.2或1.3。 – dogmatic69

+0

是的,我想的很多,這就是爲什麼我試圖爲尋求新鮮答案的人提供'最新'信息。 – klaar