So i have the following relation:
User:
<?php
App::uses('AppModel', 'Model');
/**
* User Model
*
* @property Roles $Roles
*/
class User extends AppModel {
public $actsAs = array('Acl' => array('type' => 'requester'));
public $belongsTo = array('Role');
public function parentNode() {
if (!$this->id && empty($this->data)) {
return null;
}
if (isset($this->data['User']['role_id'])) {
$roleId = $this->data['User']['role_id'];
} else {
$roleId = $this->field('role_id');
}
if (!$roleId) {
return null;
} else {
return array('Role' => array('id' => $roleId));
}
}
/**
* Display field
*
* @var string
*/
public $displayField = 'username';
public function beforeSave($options = array()) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
return true;
}
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
}
Role:
<?php
App::uses('AppModel', 'Model');
class Role extends AppModel {
public $actsAs = array('Acl' => array('type' => 'requester'));
public function parentNode() {
return null;
}
public $displayField = 'name';
}
I have setup the Aro and aco tables in my database. Now when ever i try to add a user i get the following error message:
AclNode::node() - Couldn't find Aro node identified by "Array ( [Aro0.model] => Role [Aro0.foreign_key] => 1 ) "
I feel like ive tried everything.
Does anyone know why this is happening?
My save logic (Add action):
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->saveAll($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
$roles = $this->User->Role->find('list');
$this->set(compact('roles'));
}
Error message and stacktrace:
2013-09-13 14:28:56 Error: [CakeException] AclNode::node() - Couldn't find Aro node identified by "Array
(
[Aro0.model] => Role
[Aro0.foreign_key] => 1
)
"
Request URL: /udlejnings-priser/cake/users/add
Stack Trace:
#0 /var/www/udlejnings-priser/cake/lib/Cake/Model/Behavior/AclBehavior.php(92): AclNode->node(Array)
#1 /var/www/udlejnings-priser/cake/lib/Cake/Model/Behavior/AclBehavior.php(110): AclBehavior->node(Object(User), Array, 'Aro')
#2 [internal function]: AclBehavior->afterSave(Object(User), true, Array)
#3 /var/www/udlejnings-priser/cake/lib/Cake/Utility/ObjectCollection.php(132): call_user_func_array(Array, Array)
#4 [internal function]: ObjectCollection->trigger(Object(CakeEvent))
#5 /var/www/udlejnings-priser/cake/lib/Cake/Event/CakeEventManager.php(248): call_user_func(Array, Object(CakeEvent))
#6 /var/www/udlejnings-priser/cake/lib/Cake/Model/Model.php(1789): CakeEventManager->dispatch(Object(CakeEvent))
#7 /var/www/udlejnings-priser/cake/lib/Cake/Model/Model.php(2270): Model->save(Array, Array)
#8 /var/www/udlejnings-priser/cake/lib/Cake/Model/Model.php(2073): Model->saveAssociated(Array, Array)
#9 /var/www/udlejnings-priser/cake/app/Controller/UsersController.php(82): Model->saveAll(Array)
#10 [internal function]: UsersController->add()
#11 /var/www/udlejnings-priser/cake/lib/Cake/Controller/Controller.php(490): ReflectionMethod->invokeArgs(Object(UsersController), Array)
#12 /var/www/udlejnings-priser/cake/lib/Cake/Routing/Dispatcher.php(187): Controller->invokeAction(Object(CakeRequest))
#13 /var/www/udlejnings-priser/cake/lib/Cake/Routing/Dispatcher.php(162): Dispatcher->_invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse))
#14 /var/www/udlejnings-priser/cake/app/webroot/index.php(110): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#15 {main}
My Post request
Data = {array}[1]
User = {array}[3]
username = test2
password = test
role_id = 1
Cake version 2.4.0