haskell-webapps icon indicating copy to clipboard operation
haskell-webapps copied to clipboard

Discussion: Should domain API take primary key as an argument or the entire record?

Open saurabhnanda opened this issue 8 years ago • 2 comments

should functions like activateTenant or editProduct take a TenantID or ProductID as input OR Tenant or Product

saurabhnanda avatar Oct 15 '16 04:10 saurabhnanda

Tenant vs TenantID, Requiring a Tenant seems to indicate a select before an update. the Tenant record needs to be populated, then modified based on the query params, then finally sent back across the domain API for an update. You can say semantics indicate the Tenant record is just the differences between what's in the db and the current object, so just update the populated fields. That approach seems confusing for insert though. I like ID, but i'd like to see a slick alternative.

jfoutz avatar Oct 15 '16 04:10 jfoutz

The semantics of those are quite different. A Tenant is a pure Haskell value, while a TenantId is a reference to a mutable resource. This distinction makes which to use when quite clear. If you are only performing pure transformations to a value, then Tenant should be used. Otherwise you need TenantId

wz1000 avatar Oct 15 '16 09:10 wz1000