Se abbiamo definito 2 semplici oggetti nel nostro file modelli, ad esempio: -Come definire un campo su un modulo applicativo per una chiave esterna in Yesod?
Person
name Text
Age Int
Book
title Text
author Text
Possiamo definire un modulo applicativo per Book come: -
addBookForm = renderDivs $ Book
<$> areq textField "title" Nothing
<*> areq textField "author" Nothing
Tuttavia, se vogliamo cambiare l'autore da solo un campo di testo, per l'id di una persona, come: -
Book
title Text
author PersonId
Poi il modulo di cui sopra non si compila, con questo errore: -
Couldn't match expected type `KeyBackend Database.Persist.GenericSql.Raw.SqlBackend Person' with actual type `Text'
Expected type: Field
sub0
master0
(KeyBackend Database.Persist.GenericSql.Raw.SqlBackend Person)
Actual type: Field sub0 master0 Text
In the first argument of `areq', namely `textField'
In the second argument of `(<*>)', namely
`areq textField "author" Nothing'
Come definiamo ora il campo autore? Abbiamo bisogno di usare una forma monadica?
Grazie!