Haskell Yesod:尝试打印表数据并从另一个表获取外键信息
我正在与Yesod合作,我正在尝试打印一个包含事件列表和它们所属城市的表格 我有以下型号:Haskell Yesod:尝试打印表数据并从另一个表获取外键信息,haskell,yesod,Haskell,Yesod,我正在与Yesod合作,我正在尝试打印一个包含事件列表和它们所属城市的表格 我有以下型号: City name Text countryId CountryId UniqueCity name deriving Eq deriving Show Event title Text description Text date UTCTime cityId CityId deriving Eq deriving
City
name Text
countryId CountryId
UniqueCity name
deriving Eq
deriving Show
Event
title Text
description Text
date UTCTime
cityId CityId
deriving Eq
deriving Show`
以及处理程序中的以下代码:
`module Handler.Event where
import Import
import Yesod.Form.Bootstrap3
import Database.Persist.Sql
getEventR :: Handler Html
getEventR = do
events <- runDB $ selectList [] [Asc EventTitle]
defaultLayout $ do
setTitle "Events"
[whamlet|
<h1>Events
<table>
<thead>
<tr>
<th>Event title</th>
<th>Event date</th>
<th>Event city</th>
<tbody>
$forall Entity eventId event <- events
<tr>
<td>#{eventTitle event}
<td>#{show (eventDate event)}
<td>#{addCity eventId}
|]
addCity event = do
city <- getCity $ eventCityId event
return city
getCity cid = do
city <- runDB $ get404 cid
return city`
module Handler.Event where
import Import
import Yesod.Form.Bootstrap3
import Database.Persist.Sql
getEventR :: Handler Html
getEventR = do
events <- runDB $ selectList [] [Asc EventTitle]
defaultLayout $ do
setTitle "Events"
[whamlet|
<h1>Events
<table>
<thead>
<tr>
<th>Event name</th>
<th>Event date</th>
<th>Event city</th>
<ul>
<tbody>
$forall ev <- map entityVal events
<tr>
<td>#{eventTitle ev}
<td>#{show (eventDate ev)}
<td>#{addCity ev}
|]
addCity ev = do
eve <- entityVal ev
city <- getCity $ eventCityId eve
return city
getCity cid = do
city <- runDB $ get404 cid
return $ cityName city
Couldn't match expected type 'Entity (HandlerT site0 IO Event)' with actual type 'Event'
In the first argument of 'addCity', namely 'ev_ajRc'
In the first argument of 'toHtml', namely 'addCity ev_ajRc'