I have recipes and I have ingredient_lists. A single recipe has many
entries in the ingredient_lists table. When I pull back the recipe I
want to get it's ingredient_list but I cant see quite how to do it.
This is the 'edit' action of the RecipesController:
function edit($id = null)
{
$this->Recipe->id = $id;
$this->set_recipe_types();
$this->set_ingredients();
$this->set_measurement_types();
$this->set('ingredient_list', $this->IngredientList->find('WHERE
recipe_id = ' . $id));
if (empty($this->data))
{
$this->data = $this->Recipe->read();
}
else
{
if ($this->Recipe->save($this->data))
{
$this->flash('Your recipe has been
updated.','/recipes');
}
}
}
The line that sets the 'ingredient_list' var only pulls back a single
record because of the limit clause. How do I pull back all the
records? Here is the query for ingredient_list
SELECT `IngredientList`.`recipe_id`, `IngredientList`.`ingredient_id`,
`IngredientList`.`amount`, `IngredientList`.`measurement_type_id`,
`IngredientList`.`description`, `IngredientList`.`created`,
`IngredientList`.`modified` FROM `ingredient_lists` AS
`IngredientList` WHERE recipe_id = 0000000017 LIMIT 1
Here are all the queries run for the edit page:'
DESCRIBE `recipes`
DESCRIBE `recipe_types`
DESCRIBE `ingredients`
DESCRIBE `measurement_types`
DESCRIBE `ingredient_lists`
SELECT `RecipeType`.`id`, `RecipeType`.`recipe_type` FROM
`recipe_types` AS `RecipeType` WHERE 1 = 1 ORDER BY
`RecipeType`.`recipe_type` ASC
SELECT `Ingredient`.`id`, `Ingredient`.`ingredient` FROM `ingredients`
AS `Ingredient` WHERE 1 = 1 ORDER BY `ingredient` ASC
SELECT `MeasurementType`.`id`, `MeasurementType`.`measurement_type`
FROM `measurement_types` AS `MeasurementType` WHERE 1 = 1 ORDER BY
`measurement_type` ASC
SELECT `IngredientList`.`recipe_id`, `IngredientList`.`ingredient_id`,
`IngredientList`.`amount`, `IngredientList`.`measurement_type_id`,
`IngredientList`.`description`, `IngredientList`.`created`,
`IngredientList`.`modified` FROM `ingredient_lists` AS
`IngredientList` WHERE recipe_id = 0000000017 LIMIT 1
SELECT `Recipe`.`id`, `Recipe`.`recipe`, `Recipe`.`description`,
`Recipe`.`instructions`, `Recipe`.`servings`,
`Recipe`.`recipe_type_id`, `Recipe`.`created`, `Recipe`.`modified`
FROM `recipes` AS `Recipe` WHERE `Recipe`.`id` = '0000000017' LIMIT 1
Here is the edit view
<h1>Edit Recipe</h1>
<?php
echo $form->create('Recipe', array('action' => 'edit'));
echo $form->input('Recipe.recipe');
echo $form->input('Recipe.servings', array('maxlength' => 5, 'size' =>
5));
echo $form->label('Recipe.servings', 'Recipe Type');
echo $form->select('Recipe.recipe_type_id', $recipe_types);
?>
<div>
<h2>Ingredient List</h2>
<table>
<tr>
<td><?php echo $form->input('IngredientList.amount'); ?></td>
<td><?php
echo $form->label('IngredientList.measurement_type_id',
'Measurement Type');
echo $form->select('IngredientList.measurement_type_id',
$measurement_types);
?></td>
<td><?php echo $form->input('IngredientList.description');
?></td>
<td><?php
echo $form->label('IngredientList.ingredient_id',
'Ingredient');
echo $form->select('IngredientList.ingredient_id',
$ingredients);
?></td>
</tr>
</table>
<h2>Instructions and Description</h2>
<?php
echo $form->input('Recipe.description', array('rows' => '3'));
echo $form->input('Recipe.instructions', array('rows' => '3'));
echo $form->end('Save Recipe');
?>
Thanks.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---