Guess this must be impossible. On Feb 5, 3:33 pm, RhythmicDevil <[email protected]> wrote: > Hi, > having some problems understanding how to create an association > between two existing records. The scenario is the following. I have > recipes and menus. When viewing a recipe I want the user to be able to > select a menu from a list to add the recipe to. (Menus contain > Recipes). So once again, the recipe and the list of menus already > exist. > > When I submit the data to the Menu->save() method it complains that I > am missing fields. This would make sense if I was creating a new menu > and associating recipes at the same time, but I am not. All that needs > to happen is to insert a new record into menus_recipes (join table) > that has the recipe_id and menu_id. In concept this is simple but > something about model associations is eluding me. > > This is the top of the recipe view file where I create a form to send > the menu_id and the recipe_id: > > <h1>Recipe</h1> > <div> > <label>Recipe</label> > <?php > echo $recipe['Recipe']['recipe']; > $form->create('Menu', array('url'=>'/menus/add_recipe')); > echo $form->input('Recipe.recipe_id', array('value'=> > $recipe['Recipe']['id'], 'label'=>false, 'type'=>'hidden')); > echo $form->input('Menu.menu_id'); > $form->end('Add to Menu'); > ?> > </div> > > Here is menus_controller add_recipe: > public function add_recipe() > { > var_dump($this->data); > $this->Menu->saveAll($this->data); > $this->Session->setFlash('The recipe has been added to the > menu'); > $this->redirect(array('controller'=>'recipes', > 'action'=>'index')); > } > > I am probably going to just write a raw SQL statement to take care of > this but I would really like to know the correct Cake methodology for > this. I honestly have read the docs and cant find what I am looking > for, which probably means I am looking for the wrong thing. If you are > really interested here is a link to the source code in Google's > project hosting:http://code.google.com/p/menurecipemanager/ > > Thanks for any help or advice.
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
