嗯,我没有看到任何错误的代码和表,但我有麻烦显示我需要的数据。
假设表已经创建并填充,下面是我得到的:
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'
)
),
....
}
有什么问题吗?我还需要将用户配置文件与其匹配的业务记录一起显示。请帮助。我在谷歌上搜索了答案,但我在编码相同的行,所以我不知道问题在哪里。
您没有按照Cake约定创建关系。
public $hasOne = array(
'user_profiles' => array(
'className' => 'profiles',
'foreignKey' => false,
'conditions' => array('Business.business_id = profiles.user_id')
));
和
public $hasOne = array(
'UserProfile' => array(
'className' => 'Profile',
'foreignKey' => false,
'conditions' => array('Business.business_id = Profile.user_id')
));