我有 3 个模型
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
我想访问所有的房子。我可以通过这样做
getHouseR :: Handler Value
getHouseR = do
houses <- runDB $ selectList [] [Asc HouseRent]
return $ toJSON houses
但我只参考其他实体,如person & address
.
[{"rent":8000,"addressId":4,"ownerId":1,"id":3},{"rent":10000,"addressId":2,"ownerId":1,"id":1}]
我想获得房屋的完整信息,这意味着,解决这个问题ownerId & addressId
并发送可能看起来像的数据,
[{"rent":8000,"address":{"number": "23", "street": "12/B", "pincode": "111111"},"owner":{"email": "hey@email.com", "name": "Moto", "telephone": "xxxxxxxxxx"},"id":3}]
有什么方法可以getForiegnData
向查询中添加信息,并且可以获取所有这些信息吗?或任何其他解决方案?