BWStearns
BWStearns

Reputation: 2706

Yesod return whole Entity after insert?

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?

Upvotes: 1

Views: 175

Answers (2)

Norrius
Norrius

Reputation: 7920

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

Upvotes: 1

bergey
bergey

Reputation: 3071

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

Upvotes: 2

Related Questions