Jon and Brendon, Thank you for the answers.
In my case, there some code between find() and create(). Just some ifs that I´m not showing here. What I want is create a new record, and that´s why I call the funtion create() empty; Of course I could send $this->data to create function and call save() (empty). Anyway, I spent some time looking in model.php file of libs folder and I found that Cake verifies a variable named __exists right before put the date in 'created' column. Normaly it is null or false, but right after a find() it becomes true if something is found. Thats why 'created' is NULL in this case. I think that create() function should reset this variable either. On Apr 29, 7:58 am, Jon Bennett <[email protected]> wrote: > Hi Daniel, > > > I´m sure that $this->data['MyModel']['created'] is not set. > > In your example you were not resetting the created or modified values. > > > And the function create() resets any data setted in Model. > > Yes and no. If you're creating a record, you should pass > $this->Model->create($data); your data, which internally resets any > behaviours, calls validation and sets the data in teh model. > You then simply call $this->Model->save(); without any params to save. > If you're updating a record, you should call $this->Model->set($data); > before save, which does the same thing. IMO the docs are a little > misleading on this point (not read up on create/set/save for a long > long time!). > > When copying existing records, it's always advisable to explicitly > reset any values you want to revert to defaults, unless you've > explicitly not included those fields in the find()/read(). > > hth > > Jon > > -- > > jon bennett > w:http://www.jben.net/ > iChat (AIM): jbendotnet Skype: jon-bennett On Apr 29, 10:24 am, Brendon Kozlowski <[email protected]> wrote: > Why does `cake bake` have that reversed? > > $this->Model->create(); //empty > $this->Model->save($this->data); //filled with sent data > > ?? > > Also, is Daniel trying to update the found model (if found), or create > a new model? I don't understand the reason for calling > $this->Model->findById($id); in this instance. I have a feeling that Jon was > > assuming an additional record created from already existing data > within a different record (i.e.: copy), but is that correct? > > On Apr 29, 6:58 am, Jon Bennett <[email protected]> wrote: > > > Hi Daniel, > > > > I´m sure that $this->data['MyModel']['created'] is not set. > > > In your example you were not resetting the created or modified values. > > > > And the function create() resets any data setted in Model. > > > Yes and no. If you're creating a record, you should pass > > $this->Model->create($data); your data, which internally resets any > > behaviours, calls validation and sets the data in teh model. > > You then simply call $this->Model->save(); without any params to save. > > If you're updating a record, you should call $this->Model->set($data); > > before save, which does the same thing. IMO the docs are a little > > misleading on this point (not read up on create/set/save for a long > > long time!). > > > When copying existing records, it's always advisable to explicitly > > reset any values you want to revert to defaults, unless you've > > explicitly not included those fields in the find()/read(). > > > hth > > > Jon > > > -- > > > jon bennett > > w:http://www.jben.net/ > > iChat (AIM): jbendotnet Skype: jon-bennett > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
