First the quickfix... hopefully. This will try to save a PHP-null value. $this->data['ingredient_group_id'] = null;
Instead try to save an SQL-null value. $this->data['ingredient_group_id'] = 'null'; Or even just a zero if the above doesn't work. $this->data['ingredient_group_id'] = '0'; Now for a suggestion. For saving a single field Cake models have a special function... called saveField no less :) $this->Ingredient->id = $id; // this line if very very important $successful = $this->Ingredient->saveField ('ingredient_group_id','null'); // or 0 And finally another suggestion. You don't have to call a method in one controller from another for this... Better to put the whole "removeFromGroup()" method into the Model and call it from wherever. You know you can call a model like: $this->IngredientGroup->Ingredient right? ... and by answering I am not implying I am a God of any kind ;) /Martin On Oct 17, 7:56 am, Will Poillion <lorew...@gmail.com> wrote: > Just trying to update a single field within a function called from its > associated model: > > I'm calling 'removeFromGroup' in Ingredients controller from my > IngredientGroups controller. > > I basically want to remove the ingredient from the group, so set the > ingredient_group_id to null. > > function removeFromGroup($id = null, $group_id = null) { > if (!$id) { > $this->Session->setFlash(__('Invalid id for > Ingredient', true)); > $this->redirect(array('controller'=> > 'IngredientGroups', > 'action'=>'view', $group_id)); > } > > $this->data = $this->Ingredient->read(null, $id); > > $this->data['ingredient_group_id'] = null; > $this->Ingredient->save($this->data); > $this->redirect(array('controller'=> 'IngredientGroups', > 'action'=>'view', $group_id)); > > } > > There's my function. It just won't save the ingredient_group_id to > null. Not sure what I'm doing wrong. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---