Basically right now I run fbId <- runDB $ insert myNewFooBar and I get back a Key FooBar. Is there any way to return the value of the whole FooBar directly from an insert without running a separate query of runDB $ get404 fbId after?
Yesod return whole Entity after insert?
190 Views Asked by BWStearns At
2
There are 2 best solutions below
0
On
Another, shorter option is to use insertEntity, which returns an entity instead of a record. Under the hood this function calls insert and builds an entity from the supplied record and the returned key (no additional DB queries).
insertedFooBar <- runDB $ insertEntity myNewFooBar
I just build the
EntityHaskell-side:Entity fbId myNewFooBar.