Monday, June 29, 2009

Re: 'add' action and auto-setting model id

Yes, whether it is right or not, that is the way cake behaves. You should
always use Model::create() before saving a new record just in case.

For the extra paranoid, you can do this on your add() action:

$this->Model->create($this->data, false);
$this->Model->save();

The second parameter (false) means that if there is an id set in $this->data
then it will be reset, so an insert will always occur.

Cheers,
Adam

----- Original Message -----
From: "Raph" <rafal@epoczta.pl>
To: "CakePHP" <cake-php@googlegroups.com>
Sent: Monday, June 29, 2009 10:14 PM
Subject: 'add' action and auto-setting model id


>
> I have weird (I think) problem. When I've added "add()" action to the
> contoller, the id of coresponding model has been set automaticlly to
> "add()" method parameter, and when I try to save data using that
> action update instead of save is made.
>
> This method singature looks like this:
>
> public function add($someId).
>
> Is it normal behavior? Do I have to manually call "create()" method in
> my model if I want to save, not update data?
> >
>
>


--~--~---------~--~----~------------~-------~--~----~
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: