Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In terms of best practice / a more elegant way to do this, you should look at creating a Recipe case class to hold all the info for your recipe; this will make your code a little cleaner and easier to work with:</p> <pre><code>case class Recipe(val id: Long, val cuisine: String, val instructions: String, val quantity: Int, val units: String, val brand: String, val name: String) </code></pre> <p>Note: all the fields are explicitly labeled as vals for ease of use when I access the fields in the view. You can then transform your queries into an object (from <a href="https://stackoverflow.com/questions/13097492/scala-slick-query-return-value">scala slick query return value</a>)</p> <pre><code>def getRecipe(recID: Long): Option[Recipe] = { val q = for { r &lt;- Recipes if r.id === recID ri &lt;- RecipeIngredient if ri.recID === recID i &lt;-Ingredients if i.id === ri.ingID } yield (r.id, r.cuisine, r.instructions, ri.quantity, ri.units, i.brand, i.name) q.firstOption map { case (id, cui, ins, qua, uni, bra, na) =&gt; Recipe(id, cui, ins, qua, uni, bra, na) } } </code></pre> <p>You can then pass this to your view: </p> <pre><code>@(message: String, recipe: Recipe) @main("Site name") { @recipe match { case r:Some(Recipe) =&gt; { &lt;h2&gt;--Recipe--&lt;/h2&gt; RecID: @r.id &lt;br&gt; Cuisine: @r.cuisine &lt;br&gt; Instructions: @r.instructions &lt;br&gt; &lt;h2&gt;--Ingredients--&lt;/h2&gt; Ingredient: @r.quantity @r.units of @r.brand @r.name&lt;br&gt; } case None =&gt; { &lt;h2&gt;No Recipe&lt;/h2&gt; } } } </code></pre> <p>You can do some different things, like make a companion object class for the Recipe case class, get rid of the Option[Recipe] being passed to your view, etc. This will also make it easier should you want to select multiple recipes and pass them in a List[Recipe] to a view which you could then iterate over.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload