haskell - How should get value an other table by foreing key in hamlet? -
haskell - How should get value an other table by foreing key in hamlet? -
i have info book , author, , books has foreign key authorid. list out books db. need name of author book entity has id of author why utilize get
function author data, in hamlet file not name of author, because get
function homecoming maybe author.
let see code :
book isbn text title text description textarea maybe author authorid uniquebook isbn author name text uniqueauthor name
the function of request:
getbooklistr :: handler html getbooklistr = books <- rundb $ selectlist [booktitle !=. ""] [] defaultlayout $ $(widgetfile "booklistpage")
the booklistpage hamlet file content:
$if not $ null books <table .table> $forall entity bookid book <- books <tr> <th th rowspan="4">image <td> #{booktitle book} <tr> <td> $maybe author <- (bookauthor book) #{authorname author} <tr> <td> #{bookisbn book} <tr> <td> $maybe description <- bookdescription book #{description}
this part of code has problem
<td> $maybe author <- (bookauthor book) #{authorname author}
i got error:
handler\booklist.hs:9:19: couldn't match expected type `author' actual type `maybe author' in first argument of `authorname', namely `author_afbta' in first argument of `tohtml', namely `authorname author_afbta' in first argument of `aswidgett . towidget', namely `tohtml (authorname author_afbta)'
i thought $maybe help me, perhaps misunderstand concept. understand why code not work, , solution these kind of cases, when have key when iterate in hamlet file.
thanks!
i added chapter on sql joins yesod book, covers case.
haskell persistence yesod
Comments
Post a Comment