So I have a really odd problem that i can't figure out. This one column won't update on ->save().
I have tested it like this. this is in my edit action.
$account = Accounts::findFirstById($id);
//...... some logic here
$edit = $this->request->getPost();
$update = array();
foreach($edit as $k => $v){
$update[$k] = htmlspecialchars($v);
}
// First output below.
$account->assign($update);
// second output below, notice the userId has changed as the asignment should have done it.
if (!$account->save()) {
$this->flash->error($account->getMessages());
} else {
// Third output here. So no error happend, but the userId is now back to its original value....
$this->flashSession->success("User was updated successfully");
$this->response->redirect('accounts/view/'.$account->id);
}
FIRST DUMP - befor ethe assign.
Array
(
[id] => 83
[name] => this is insaneasdfasdfasdf
[phone] => xxx-xxx-xxxx
[email] => [email protected]
[accountId] =>
[userId] => 6
)
SECOND DUMP - after the assign.
Array
(
[id] => 83
[name] => this is insaneasdfasdfasdf
[phone] => xxx-xxx-xxxx
[email] => [email protected]
[accountId] =>
[userId] => 8
)
THIRD DUMP - after save
Array
(
[id] => 83
[name] => this is insaneasdfasdfasdf
[phone] => xxx-xxx-xxxx
[email] => [email protected]
[accountId] =>
[userId] => 6
)
So i was curious if it had something to do wtih my relationals listed on the account or user model.
To test this i changed the ID of userId, to a user that disnt' exist. in my case id 7. Doing this makes it so that i can change value. When the alvue is set to an existing user i have this extra bit in the dump the id being the same as the id that won't change seemd suspicious.
[_uniqueKey:protected] => `id` = ?
[_uniqueParams:protected] => Array
(
[0] => 6
)
[_uniqueTypes:protected] => Array
(
[0] => 6
)
here is my instantiation in account model
public function initialize()
{
$this->belongsTo("userId", "Nova\Models\Users", "id", array(
'alias' => 'accountOwner'
));
$this->belongsTo("createdBy", "Nova\Models\Users", "id", array(
'alias' => 'createdName'
));
$this->hasMany('id', 'Nova\Models\AccountingLineItems','accountId', array(
'alias' => 'accountingLineItems'
));
$this->hasMany("id", "Nova\Models\Payments", "accountId", array(
'alias' => 'payments',
'foreignKey' => array(
'message' => 'This account cannot be deleted because it has payments'
)));
$this->hasMany('id','Nova\Models\AccountStatus','accountId',array(
'alias' => 'accountStatus'
));
$this->hasMany('id','Nova\Models\Notes','accountId', array(
'alias' => 'notes'
));
$this->hasMany('id', 'Nova\Models\Tasks', 'accountId', array(
'alias' => 'tasks'
));
$this->hasMany('id','Nova\Models\Files','objectId', array(
'alias' => 'files',
'params' => array(
'conditions' => "type = 'account'"
)));
$this->hasMany('id','Nova\Models\AccountSettings','accountId',array(
'alias'=>'accountSettings'
));
}
And here is hte user. its large :P
public function initialize(){
$this->belongsTo('userRegionalId', 'Nova\Models\Users', 'id',
array('alias' => 'regional'
));
$this->belongsTo('userManagerId', 'Nova\Models\Users', 'id',
array('alias' => 'manager'
));
$this->belongsTo('userRecruiterId', 'Nova\Models\Users', 'id',
array('alias' => 'recruiter'
));
$this->hasMany('id', 'Nova\Models\Users', 'userRegionalId',
array('alias' => 'regionalSubs'
));
$this->hasMany('id', 'Nova\Models\Users', 'userManagerId',
array('alias' => 'managerSubs'
));
$this->hasMany('id', 'Nova\Models\Users', 'userRecruiterId',
array('alias' => 'recruiterSubs'
));
$this->belongsTo('profilesId', 'Nova\Models\Profiles', 'id', array(
'alias' => 'profile',
'reusable' => true
));
$this->hasMany("id", "Nova\Models\Accounts", "userId", array(
'alias' => 'accounts',
'reusable' => true
));
$this->hasMany('id', 'Nova\Models\SuccessLogins', 'usersId', array(
'alias' => 'successLogins',
'foreignKey' => array(
'message' => 'User cannot be deleted because he/she has activity in the system'
)
));
$this->hasMany('id', 'Nova\Models\PasswordChanges', 'usersId', array(
'alias' => 'passwordChanges',
'foreignKey' => array(
'message' => 'User cannot be deleted because he/she has activity in the system'
)
));
$this->hasMany('id', 'Nova\Models\ResetPasswords', 'usersId', array(
'alias' => 'resetPasswords',
'foreignKey' => array(
'message' => 'User cannot be deleted because he/she has activity in the system'
)
));
$this->hasMany('id', 'Nova\Models\Payments', 'accountUserId', array(
'alias' => 'payments',
'foreignKey' => array(
'message' => "user cannot be dleted because he has payments assigned to him"
)));
$this->hasMany('id', 'Nova\Models\Draws', 'userId', array(
'alias' => 'draws',
'foreignKey' => array(
'message' => 'user cannat be deleted because he/she has draws'
)));
$this->hasMany('id', 'Nova\Models\Accounts', 'userId', array(
'alias' => 'accounts',
'foreignKey' => array(
'message'=> 'This user still has accounts assigned to it'
)));
// FILES HERE
$this->hasMany('id','Nova\Models\Files','objectId', array(
'alias' => 'files',
'params' => array(
'conditions' => "type = 'user'"
)));
$this->hasOne('id','Nova\Models\Files', 'objectId', array(
'alias' => 'userImage',
'params' => array(
'conditions' => "type = 'userImage'"
)));
$this->hasMany('id','Nova\Models\Files', 'objectId',array(
'alias' => 'userIdImages',
'params' => array(
'conditions' => "type = 'userIdImages'"
)));
$this->hasMany('id','Nova\Models\Files', 'objectId', array(
'alias' => 'userAgreementFiles',
'params' => array(
'conditions' => "type = 'userAgreementFiles'"
)));
$this->hasMany('id', 'Nova\Models\UsersCompliance','userId',array(
'alias' => 'usersCompliance',
'foreignKey' => array(
'action' => Relation::ACTION_CASCADE
)));
}