I tried to setup relationships between models Users and Groups via Users_Group using different methods, with and without namespace, with hasManyToMany and hasMany etc. nothing works and gives me error:
Fatal error: Class 'Users_Groups' not found ...
Here is my UserController portion:
public function registerAction()
{
$user = new Users();
$password = $this->security->hash($this->request->getPost('password'));
$signup = array(
'name'=>$this->request->getPost('name'),
'username'=>$this->request->getPost('username'),
'email'=>$this->request->getPost('email'),
'password'=>$password,
'active'=>'Y',
'datetime'=>date('Y-m-d H:i:s', time())
);
//Store and check for errors
$success = $user->save($signup, array('name', 'username', 'email', 'password', 'active', 'datetime'));
$group = Groups::findByName('user');
$userGroup = new Users_Groups();
$userGroup->user_id = $user->getId();
$userGroup->group_id = $group->getId();
$groupSuccess = $userGroup->save();
if ($success && $groupSuccess) {
echo "Thanks for registering!";
} else {
echo "Sorry, the following problems were generated: ";
foreach ($user->getMessages() as $message) {
echo $message->getMessage(), "<br/>";
}
}
$this->view->disable();
}
Here is Users model:
public function initialize()
{
$this->hasMany(
'id',
'Users_Groups',
'user_id'
);
$this->hasMany('id','Qsos','user_id');
$this->hasMany('id','Configs','user_id');
}
Here is Groups model:
public function initialize()
{
$this->hasMany(
'id',
'Users_Groups',
'group_id'
);
}
And finally Users_Groups model
public function initialize()
{
$this->belongsTo('user_id','Users','id');
$this->belongsTo('group_id','Groups','id');
}
Please help! It drives me crazy!