Hi Ryan,
1: Not that I am aware of. It is a very good idea for a page in the
cookbook, though.
2: This is usually very simple. Sometimes you have to watch out
though.
Usually this is totally automatic.
$one = $this->ExampleModel->findById($id);
$one['ExampleModel']['example_field'] = 0;
$this->ExampleModel->save($one);
Cake will know to use update in most cases like in the example above.
Sometimes, though you will have to help out a little. Like when you
are looping a number of records and saving each in turn, you must call
create before each save to avoid saving over the same record each
time.
There is also sometimes call for these drastic measuers.
You may not always be sure wether insert of create should be used:
$one = $this->ExampleModel->findById($id);
if ( empty($one) ) {
$one = array('ExampleModel'=>array());
}
$one['ExampleModel']['example_field'] = 0;
$this->ExampleModel->create();
$this->ExampleModel->set($one);
$this->ExampleModel->save($one);
That is, I think, it. Some people prefer setting the id of a Model
before using set(). I have seen tests in the core using both methods
so I guess both work fine. When I have done similar saves I have not
found it necessary setting Model->id before using set(). It may depend
on circumstances I am not fully aware of.
/Martin
On Oct 6, 6:51 pm, Ryan <[EMAIL PROTECTED]> wrote:
> As a new Cake user, I am having a bit of trouble transitioning from
> writing my own MySQL queries, to letting Cake do the heavy lifting for
> me. I think I have SELECT and INSERT down, but am still struggling
> with UPDATE. Two questions:
>
> 1.) Is there a good resource I can refer to that shows examples of raw
> SQL with the cake equivalent? This would really help my learning.
>
> 2.) The specific issue I am having that prompted this thread... I've
> got a primary key id number for a record in a table, and for that
> record, I want to update change the value of a given field from 1 to
> 0. How can I perform that simple operation with a Cake query?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---