Yesod return whole Entity after insert?

179 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

I just build the Entity Haskell-side: Entity fbId myNewFooBar.

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