Reputation: 2781
I am trying to load another model in one default model. I have a profiles table in my database. but getting error.
User model
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
public function getProfileData(){
$this->loadModel('Profile');
$profileData = $this->Profile->findById('8');
print_r($profileData);
}
}
Error :
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'loadModel' at line 1
SQL Query: loadModel
Upvotes: 0
Views: 147
Reputation: 947
Perhaps the Profile model is associated with the User model already. If that's the case, you can access it using:
$this->User->Profile->findById(8);
without the need to load anything.
Upvotes: 0
Reputation: 1263
There is another way.
$profile= ClassRegistry::init('Profile');
$profileData = $profile->findById(8);
Upvotes: 1