Re: app attempting to insert records rather than update
Thanks, Brian for all your input. I agree, the code was pretty difficult to understand. After spending tons of time staring at the code, I realized there was a simpler and more correct way to do it. I rewrote it and it's working for the most part now. I still have to work out a few kinks, though. Jon Chin brian wrote: That's a bit difficult to follow. At what point are you calling _processMerit()? And you have an empty block inside wizard()? Is that on purpose? You have a couple of instances with $this->Merit->save($this->data) but I only see where you're reading data from the DB for Application. hich model are you working with? Sorry, I've never used the WizardComponent so this is a bit opaque to me. On Sat, Jun 20, 2009 at 2:06 AM, Jon Chin wrote: Here's the code. I still can't get it to update rather than insert. What am I doing wrong? function beforeFilter() { $this->Wizard->steps = array('profile', 'merit', 'finance', 'education', 'endorsement'); } function wizard($step = null) { if(isset($this->passedArgs['1']) || $this->Session->read('application_id')) //if application already defined, load it { //Ensure the user is authorized to edit the application if(isset($this->passedArgs['1'])) {$this->Session->write('application_id', $this->passedArgs['1']);} $application = $this->Application->findById($this->Session->read('application_id')); if($application['Application']['user_id'] == $this->Auth->user('id')) { } else { $this->Session->setFlash('You do not have authorization to view this.'); $this->Session->delete('application_id'); $this->redirect('/applications'); } } else //if not entering with previously started application, start one { //create application record $this->Application->create(); $this->Application->save(array('user_id'=>$this->Auth->user('id'))); $this->Session->write('application_id', $this->Application->getInsertID()); } $this->Wizard->process($step); } function _processMerit() { App::import('Sanitize'); Sanitize::clean($this->data); switch($this->params['form']['action']) { case 'Continue': if($this->Merit->save($this->data)) { return true; } else { $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.'); return false; } break; case 'Back': $this->redirect('/applications/wizard/profile'); break; case 'Save': if($this->Merit->save($this->data)) { $this->Session->setFlash('Your changes have been saved.'); } else { $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.'); } break; } return false; } Jon Chin brian wrote: On Fri, Jun 19, 2009 at 2:04 AM, Jon Chin wrote: Thanks for the tip. Sadly, I'm still having problems with it. When I add input('id');?> to the view, all it does is generate which doesn't change anything in my controller when I print the contents of $this->data. I also tried making the field called application_id in the form, but it didn't have an effect either. It's really stumping me. Any idea what's going on? Since my primary key on Merit is application_id, should Cake already know that if I'm trying to set $this->Merit->id? The PK for Merit should be "id", not "application_id". That should be a foreign key pointing to applications table. If you post the code for the controller action we might be able to sort it out. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~--- smime.p7s Description: S/MIME Cryptographic Signature
Re: app attempting to insert records rather than update
That's a bit difficult to follow. At what point are you calling _processMerit()? And you have an empty block inside wizard()? Is that on purpose? You have a couple of instances with $this->Merit->save($this->data) but I only see where you're reading data from the DB for Application. hich model are you working with? Sorry, I've never used the WizardComponent so this is a bit opaque to me. On Sat, Jun 20, 2009 at 2:06 AM, Jon Chin wrote: > > Here's the code. I still can't get it to update rather than insert. > What am I doing wrong? > > function beforeFilter() { > $this->Wizard->steps = array('profile', 'merit', 'finance', > 'education', 'endorsement'); > } > > function wizard($step = null) { > if(isset($this->passedArgs['1']) || > $this->Session->read('application_id')) //if application already > defined, load it > { > //Ensure the user is authorized to edit the application > if(isset($this->passedArgs['1'])) > {$this->Session->write('application_id', $this->passedArgs['1']);} > $application = > $this->Application->findById($this->Session->read('application_id')); > > if($application['Application']['user_id'] == > $this->Auth->user('id')) > { > } > else > { > $this->Session->setFlash('You do not have authorization to > view this.'); > $this->Session->delete('application_id'); > $this->redirect('/applications'); > } > > } > else //if not entering with previously started application, start one > { > //create application record > $this->Application->create(); > $this->Application->save(array('user_id'=>$this->Auth->user('id'))); > $this->Session->write('application_id', > $this->Application->getInsertID()); > } > $this->Wizard->process($step); > } > > function _processMerit() { > App::import('Sanitize'); > Sanitize::clean($this->data); > switch($this->params['form']['action']) > { > case 'Continue': > if($this->Merit->save($this->data)) { > return true; > } > else > { > $this->Session->setFlash('Sorry, the information you\'ve > entered is incorrect.'); > return false; > } > break; > case 'Back': > $this->redirect('/applications/wizard/profile'); > break; > case 'Save': > if($this->Merit->save($this->data)) { > $this->Session->setFlash('Your changes have been saved.'); > } > else > { > $this->Session->setFlash('Sorry, the information you\'ve > entered is incorrect.'); > } > break; > } > return false; > } > > Jon Chin > > > > brian wrote: >> On Fri, Jun 19, 2009 at 2:04 AM, Jon Chin wrote: >> >>> Thanks for the tip. Sadly, I'm still having problems with it. When I >>> add input('id');?> to the view, all it does is generate >> type="hidden" name="data[Application][id]" value="" id="ApplicationId" >>> /> which doesn't change anything in my controller when I print the >>> contents of $this->data. I also tried making the field called >>> application_id in the form, but it didn't have an effect either. >>> >>> It's really stumping me. Any idea what's going on? Since my primary >>> key on Merit is application_id, should Cake already know that if I'm >>> trying to set $this->Merit->id? >>> >>> >> >> The PK for Merit should be "id", not "application_id". That should be >> a foreign key pointing to applications table. >> >> If you post the code for the controller action we might be able to sort it >> out. >> >> > >> > > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: app attempting to insert records rather than update
Here's the code. I still can't get it to update rather than insert. What am I doing wrong? function beforeFilter() { $this->Wizard->steps = array('profile', 'merit', 'finance', 'education', 'endorsement'); } function wizard($step = null) { if(isset($this->passedArgs['1']) || $this->Session->read('application_id')) //if application already defined, load it { //Ensure the user is authorized to edit the application if(isset($this->passedArgs['1'])) {$this->Session->write('application_id', $this->passedArgs['1']);} $application = $this->Application->findById($this->Session->read('application_id')); if($application['Application']['user_id'] == $this->Auth->user('id')) { } else { $this->Session->setFlash('You do not have authorization to view this.'); $this->Session->delete('application_id'); $this->redirect('/applications'); } } else //if not entering with previously started application, start one { //create application record $this->Application->create(); $this->Application->save(array('user_id'=>$this->Auth->user('id'))); $this->Session->write('application_id', $this->Application->getInsertID()); } $this->Wizard->process($step); } function _processMerit() { App::import('Sanitize'); Sanitize::clean($this->data); switch($this->params['form']['action']) { case 'Continue': if($this->Merit->save($this->data)) { return true; } else { $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.'); return false; } break; case 'Back': $this->redirect('/applications/wizard/profile'); break; case 'Save': if($this->Merit->save($this->data)) { $this->Session->setFlash('Your changes have been saved.'); } else { $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.'); } break; } return false; } Jon Chin brian wrote: > On Fri, Jun 19, 2009 at 2:04 AM, Jon Chin wrote: > >> Thanks for the tip. Sadly, I'm still having problems with it. When I >> add input('id');?> to the view, all it does is generate > type="hidden" name="data[Application][id]" value="" id="ApplicationId" >> /> which doesn't change anything in my controller when I print the >> contents of $this->data. I also tried making the field called >> application_id in the form, but it didn't have an effect either. >> >> It's really stumping me. Any idea what's going on? Since my primary >> key on Merit is application_id, should Cake already know that if I'm >> trying to set $this->Merit->id? >> >> > > The PK for Merit should be "id", not "application_id". That should be > a foreign key pointing to applications table. > > If you post the code for the controller action we might be able to sort it > out. > > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: app attempting to insert records rather than update
On Fri, Jun 19, 2009 at 2:04 AM, Jon Chin wrote: > > Thanks for the tip. Sadly, I'm still having problems with it. When I > add input('id');?> to the view, all it does is generate type="hidden" name="data[Application][id]" value="" id="ApplicationId" > /> which doesn't change anything in my controller when I print the > contents of $this->data. I also tried making the field called > application_id in the form, but it didn't have an effect either. > > It's really stumping me. Any idea what's going on? Since my primary > key on Merit is application_id, should Cake already know that if I'm > trying to set $this->Merit->id? > The PK for Merit should be "id", not "application_id". That should be a foreign key pointing to applications table. If you post the code for the controller action we might be able to sort it out. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: app attempting to insert records rather than update
What get you printed out doing a print_r($data) just before the: if ($this->Merit->save($this->data)) {return true;} ? What if you save the ID manually into $this->data ? $this->data['Application']['id'] = yourIDFromYourSession(); --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: app attempting to insert records rather than update
Thanks for the tip. Sadly, I'm still having problems with it. When I add input('id');?> to the view, all it does is generate which doesn't change anything in my controller when I print the contents of $this->data. I also tried making the field called application_id in the form, but it didn't have an effect either. It's really stumping me. Any idea what's going on? Since my primary key on Merit is application_id, should Cake already know that if I'm trying to set $this->Merit->id? Jon Chin rich...@home wrote: > Forget about storing the id in a session and just include the field in > the form. Cake will automatically hide it from the user. > > On Jun 18, 8:55 am, Jon Chin wrote: > >> I'm building a scholarship application using Cake. I have an >> Application model and a Merit model and I'm using a wizard component I >> picked up from the Bakery. The Application model has a hasOne >> relationship to Merit. I want my users to be able to come back to edit >> the stuff they've already saved to the merits table. My app works fine >> the first time a user goes through the process. The problem I'm having >> is that when they want to edit the data (btw, it loads the data from the >> db fine), it attempts to insert a new record rather than update the >> current. Here's my relevant code: >> >> In the controller: >> $this->Merit->id = $this->Session->read('application_id');//I've done a >> pr($this->Merit->id); and it is has the right application id >> if($this->Merit->save($this->data)) {return true;} >> >> In the model: >> var $name = 'Merit'; >> var $belongsTo = array('Application' => array( >> 'className'=> 'Application', >> 'foreignKey'=> 'application_id' >> )); >> >> Any advice would be greatly appreciated. I've been banging my head on >> the wall over this. >> >> Thanks, >> >> -- >> Jon Chin >> > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: app attempting to insert records rather than update
Forget about storing the id in a session and just include the field in the form. Cake will automatically hide it from the user. On Jun 18, 8:55 am, Jon Chin wrote: > I'm building a scholarship application using Cake. I have an > Application model and a Merit model and I'm using a wizard component I > picked up from the Bakery. The Application model has a hasOne > relationship to Merit. I want my users to be able to come back to edit > the stuff they've already saved to the merits table. My app works fine > the first time a user goes through the process. The problem I'm having > is that when they want to edit the data (btw, it loads the data from the > db fine), it attempts to insert a new record rather than update the > current. Here's my relevant code: > > In the controller: > $this->Merit->id = $this->Session->read('application_id');//I've done a > pr($this->Merit->id); and it is has the right application id > if($this->Merit->save($this->data)) {return true;} > > In the model: > var $name = 'Merit'; > var $belongsTo = array('Application' => array( > 'className' => 'Application', > 'foreignKey' => 'application_id' > )); > > Any advice would be greatly appreciated. I've been banging my head on > the wall over this. > > Thanks, > > -- > Jon Chin --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
app attempting to insert records rather than update
I'm building a scholarship application using Cake. I have an Application model and a Merit model and I'm using a wizard component I picked up from the Bakery. The Application model has a hasOne relationship to Merit. I want my users to be able to come back to edit the stuff they've already saved to the merits table. My app works fine the first time a user goes through the process. The problem I'm having is that when they want to edit the data (btw, it loads the data from the db fine), it attempts to insert a new record rather than update the current. Here's my relevant code: In the controller: $this->Merit->id = $this->Session->read('application_id');//I've done a pr($this->Merit->id); and it is has the right application id if($this->Merit->save($this->data)) {return true;} In the model: var $name = 'Merit'; var $belongsTo = array('Application' => array( 'className'=> 'Application', 'foreignKey'=> 'application_id' )); Any advice would be greatly appreciated. I've been banging my head on the wall over this. Thanks, -- Jon Chin --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---