Reputation: 2610
Well, I dont see anything wrong with the code and with the tables but im having trouble displaying the data i need.
given that the tables are already created and populated, here's what i got:
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')
));
}
the result as i debug it in my controller is this:
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'
)
),
....
}
what seems to be the problem? I need also to the user profiles to be displayed with its matching business record. Please help. Ive googled answers but Im coding the same lines so I dunno where the problem resides.
Upvotes: 0
Views: 6017
Reputation: 7575
You are not creating relations according to the Cake conventions.
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')
));
Upvotes: 4