Okay, I feel like an idiot.

I said:
$this->PracticeInstance->save();

instead of:
$this->PracticeInstance->save($this->data);

foolish me. The datetime fields were autopopulating because a record
was being inserted, but it had no data and those are the only fields
that get filled automatically. Everything works now. Sorry to kill
time with a slight oversight.

On Apr 15, 3:30 pm, Johnny Ferguson <[email protected]> wrote:
> a beforeSave() in the model yields:
>
> app/models/practice_instance.php (line 6)
>
> Array
> (
>     [PracticeInstance] => Array
>         (
>             [modified] => 2010-04-15 15:26:21
>             [created] => 2010-04-15 15:26:21
>         )
>
> )
>
> ---
>
> So somehow cake is rejecting members of $this->data
>
> /app/controllers/practice_instances_controller:http://pastebin.com/15wbnaqQ
>
> My save is in the add method
>
> Here's the view/form 
> (/app/views/practice_instances/add.ctp):http://pastebin.com/pGUb98ew
>
> On Apr 15, 3:01 am, Jeremy Burns <[email protected]> wrote:
>
> > Hmmm. If you don't have any validation rules my code isn't entirely 
> > applicable, but I'd still do this:
>
> > >>> if ($this->PracticeInstance->save($this->data['PracticeInstance'])):
> > >>>         --do something
> > >>> else:
> > >>>         die(debug($this->data));
> > >>> endif;
>
> > At least you'll find out if Cake thinks it has saved it correctly.
>
> > Also, try this in your model:
>
> > function beforeSave() {
> >         die(debug($this->data));
>
> > }
>
> > Might be interesting to see what is being passed out.
>
> > Can you show and tell more of the code that is calling the save?
>
> > Jeremy Burns
> > [email protected]
>
> > On 15 Apr 2010, at 07:24, Johnny Ferguson wrote:
>
> > > Now this is interesting:
>
> > > 100415  0:39:30      159 Connect   acc...@localhost on
> > >              159 Init DB   dev_practicelog
> > >              159 Query     SHOW TABLES FROM `dev_practicelog`
> > >              159 Query     DESCRIBE `practice_instances`
> > >              159 Query     DESCRIBE `practice_items`
> > >              159 Query     INSERT INTO `practice_instances` (`modified`, 
> > > `created`)
> > > VALUES ('2010-04-15 00:39:30', '2010-04-15 00:39:30')
> > >              159 Query     SELECT LAST_INSERT_ID() AS insertID
> > >              159 Quit
>
> > > It seems Cake isn't inserting the other values, even though they're
> > > showing up in my controller dump.... odd.
>
> > > On Apr 15, 2:22 am, Johnny Ferguson <[email protected]> wrote:
> > >> If I put the data in manually it sticks.
>
> > >> I don't have any validation rules.
>
> > >> I'll try the code you recommended.
>
> > >> I suppose at least if what I'm doing SHOULD work (can you confirm
> > >> this?), then I can look through my sql logs and see what's happening.
>
> > >> On Apr 15, 2:00 am, Jeremy Burns <[email protected]> wrote:
>
> > >>> Odd.
>
> > >>> What happens when you put the data straight into the table without Cake?
>
> > >>> What are the data types of the fields? Do you have any validation rules 
> > >>> in your PracticeInstance model? If not (I have experienced this before) 
> > >>> it passes Cake validation but fails at the database level, tricking 
> > >>> Cake into thinking that all is OK.
>
> > >>> Are you running this from within the practice_instances controller? If 
> > >>> so, try this:
>
> > >>> if ($this->PracticeInstance->save($this->data['PracticeInstance'])):
> > >>>         --do something
> > >>> else:
> > >>>         die(debug($this->PracticeInstance->validationErrors));
> > >>> endif;
>
> > >>> And see what pops up.
>
> > >>> Jeremy Burns
> > >>> [email protected]
>
> > >>> On 15 Apr 2010, at 05:56, Johnny Ferguson wrote:
>
> > >>>> Hi,
>
> > >>>> I'm developing an app that has database relationships.
>
> > >>>> The table in question is like so:
>
> > >>>> tbl practice_instances
> > >>>> id - int (primary)
> > >>>> created - timestamp (default: null)
> > >>>> modified - timestamp (default: null)
> > >>>> timeminutes - int
> > >>>> practice_session_id - int
> > >>>> practice_item_id - int
> > >>>> tempostart - int
> > >>>> tempofinish - int
>
> > >>>> practice_session_id refers to an entry in the PracticeSession model
> > >>>> (PracticeSession hasMany PracticeInstance)
> > >>>> practice_item_id refers to an entry in the PracticeItem model
> > >>>> (PracticeInstance belongsTo PracticeItem)
>
> > >>>> I have a form under /cakeRoot/practice_instances/add which accepts the
> > >>>> following fields:
>
> > >>>> <?php
> > >>>>    echo $form->create("PracticeInstance");
> > >>>>    echo $form->input("timeminutes");
> > >>>>    echo $form->input("practice_session_id");
> > >>>>    echo $form->input("practice_item_id");
> > >>>>    echo $form->input("tempostart");
> > >>>>    echo $form->input("tempofinish");
> > >>>>    echo $form->end("Create Practice Instance");
> > >>>> ?>
>
> > >>>> When I submit the form, I can see in my controller dump:
>
> > >>>> [data] => Array
> > >>>>                (
> > >>>>                    [PracticeInstance] => Array
> > >>>>                        (
> > >>>>                            [timeminutes] => 20
> > >>>>                            [practice_session_id] => 42
> > >>>>                            [practice_item_id] => 3
> > >>>>                            [tempostart] => 120
> > >>>>                            [tempofinish] => 128
> > >>>>                        )
>
> > >>>>                )
>
> > >>>> So everything is fine there, but when I look in my table, all the
> > >>>> fields other than id, created, and modified are set to a value of 0.
> > >>>> This is odd because cake is telling me that it saved $this->data, and
> > >>>> as you can see, the values above are not zero. I have the feeling that
> > >>>> I'm not understanding something about data relationships. Any idea why
> > >>>> these fields are getting set to 0?
>
> > >>>> In the final application users won't really create PracticeInstances
> > >>>> manually (it will be part of creating a PracticeSession), but I'd like
> > >>>> to be able to add fields for testing.
>
> > >>>> Check out the new CakePHP Questions 
> > >>>> sitehttp://cakeqs.organdhelpotherswith their CakePHP related questions.
>
> > >>>> 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 athttp://groups.google.com/group/cake-php?hl=en
>
> > >>>> To unsubscribe, reply using "remove me" as the subject.
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
> > > with their CakePHP related questions.
>
> > > 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 
> > > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

Reply via email to