HELP!!!The field can not be update

Here have 4 tables Admins, Roles , RolePermissions, RoleResources

definition below: Admins

public function initialize()  {
        $this->belongsTo('role_id','Mallex\Mvc\Models\Roles','id',array('alias' => 'Role'));
 }

Roles

public function initialize()  {
       $this->hasMany('id','Mallex\Mvc\Models\Admins','role_id',array('alias' => 'Admins'));
       $this->hasOne('id','Mallex\Mvc\Models\RoleResources','role_id',array('alias' => 'RoleResource'));
       $this->hasOne('id','Mallex\Mvc\Models\RolePermissions','role_id',array('alias' => 'RolePermission'));
}

RolePermissions

public function initialize() {
        $this->belongsTo('role_id','Mallex\Mvc\Models\Roles','id',array('alias' => 'Role'));
}

RoleResources

public function initialize() {
        $this->belongsTo('role_id','Mallex\Mvc\Models\Roles','id',array('alias' => 'Role'));
}

and now,i want to update admin's role_id,it is always return 1,the role_id field can not update...

help plz..



84.5k

Can you post please how you're doing the updating of the records?



8.3k
edited Mar '14

ok

public function updateAction() {
        if($this->request->isPost()) {
            $id = $this->request->getPost('id','int');
            $admin = \Mallex\Mvc\Models\Admins::findFirst(array(
                'conditions' => 'id = :id:',
                'bind' => array(
                    'id' => $id
                ),
                'bindType' => array(
                    'id' => \Phalcon\Db\Column::BIND_PARAM_INT
                )
            ));
            $admin->role_id = $this->request->getPost('roleid','int');
            $admin->salt = \Mallex\Mvc\Extensions\Utils::RandomChars(16,false);
            $admin->pwd = sha1(md5(md5(md5($this->request->getPost('pwd','string') . $admin->salt))));
            $admin->region_id = $this->request->getPost('regionid','int');
            $admin->truename = $this->request->getPost('truename','string');
            $admin->sex = $this->request->getPost('sex','int');
            $admin->identity = $this->request->getPost('identity','string');
            $admin->address = $this->request->getPost('address','string');
            if($admin->save()) {
                $this->flash->success($this->lang->admin->success);
                $this->dispatcher->forward(array(
                    'controller' => 'success',
                    'action' => 'show'
                ));
            } else {
                $this->flash->success($this->lang->admin->error);
                $this->dispatcher->forward(array(
                    'controller' => 'success',
                    'action' => 'show'
                ));
            }
        }
    }


8.3k

Help!!!!!!