I have 3 Models
Address json
number Text
street Text
pincode Text
deriving Show
Person json
email Text
name Text
telephone Text
deriving Show
House json
rent Int
ownerId PersonId
addressId AddressId
deriving Show
I want to access all houses. Which I can get by doing
getHouseR :: Handler Value
getHouseR = do
houses <- runDB $ selectList [] [Asc HouseRent]
return $ toJSON houses
But I get only reference to the other entities like person & address.
[{"rent":8000,"addressId":4,"ownerId":1,"id":3},{"rent":10000,"addressId":2,"ownerId":1,"id":1}]
I would like to get complete information of house, That means, resolve that ownerId & addressId and get that data sent which might look like,
[{"rent":8000,"address":{"number": "23", "street": "12/B", "pincode": "111111"},"owner":{"email": "[email protected]", "name": "Moto", "telephone": "xxxxxxxxxx"},"id":3}]
Is there any way to add an information like getForiegnData to the query and that would fetch me all this ? Or any other solution ?
I couldn't find any direct way (similar to annotations) to fetch referenced model information. But there are 2 ways we can get this done.
Create the
HouseResptype, which will represent your response body including person and address information.Then, modify
getHouseRto fetch complete information for every house by using available reference id.