Thursday, December 4, 2008

Re: Behavior can create new records but fails to update.

Got it!

I discovered that loading the existing values to overwrite was causing
the issue. If I just set the ID and only had the 2 fields I change it
worked.

That points to...
Validation!

By turning off the validation I am able to save all fields after
loading.

This works but I dont know the name of the user I am banning. :(

//set their id
$model->id=$userID; //notice we never load the existing values
//overwrite their password
$data['User']['password']='ThisUserViolatedTerms'.date('dmY');
//save new password effectively blocking them out.
//also save boolena field to lock
$data['User']['isBanned']= 1;
$model->save($data);

~~Solution~~ ignore validation

$data=$model->read(null,$userID); // here we can load all the
values.
debug($data);
//overwrite their password
$data['User']['password']='ThisUserViolatedTerms'.date('dmY');
//save new password effectively blocking them out.
//also save boolena field to lock
$data['User']['isBanned']= 1;
//$model->data=$violator;
$model->save($data,false); // the second argument ignores
validation


On Dec 4, 8:29 pm, Smelly_Eddie <OlliT...@gmail.com> wrote:
> Thanks, but unfortunately the results are the same. No update query is
> run.
>
>                 $model->id=$userID;
>                 $data=$model->read();
>                 debug($data);
>                 //overwrite their password
>                 $data['User']['password']='ThisUserViolatedTerms'.date('dmY');
>                 //save new password effectively blocking them out.
>                 //also save boolena field to lock
>                 $data['User']['isBanned']= 1;
>                 //$model->data=$violator;
>                 $model->save($data);
>
> On Dec 4, 7:57 pm, ridwan arifandi <orangerdigi...@gmail.com> wrote:
>
> > try
>
> > $model->id = $foo['User']['id']
> > $data = $model->Read();
>
> > $data['User']['...'] = xxxx;
>
> > then save
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: