Given a user, I am trying to select a list of events that are affiliated with organizations that the user is in. The UserOrg table describes which OrgIds correspond to a given UserId.
I have these tables:
User
email Text
name Text
UniqueUser email
deriving Typeable
Event
name Text
description Text
dateTime UTCTime
userId UserId
orgId OrgId
deriving Show
Org
name Text
description Text
deriving Show
UserOrg
userId UserId
orgId OrgId
Currently I am trying this:
getEventR :: Handler Html
getEventsR = do
muser <- maybeAuth
eventList <- runDB $
case muser of
Nothing -> []
(Just euser) -> selectList [ EventOrgId <-. (userOrgIds $ entityKey euser) ] []
defaultLayout $ do
setTitle "Events"
$(widgetFile "events")
userOrgIds :: UserId -> [OrgId]
userOrgIds userid = do
rows <- liftHandler $ runDB $ selectList [ UserOrgUserId ==. userid ] []
return $ [ userOrgOrgId $ entityVal $ erow | erow <- rows ]
But I get a type error saying that the return of userOrgIds returns a [[OrgId]]
rather than [OrgId]
, and concat doesn't work here
Am I going about this wrong? Should I just use rawQuery
in this case?