JSONify model in Persistent * including * identifier

Here I have a Persistent model:

Tip text Text created_at UTCTime updated_at UTCTime title Text category_id CategoryId 

And the related ToJSON instance (I could not use deriveJSON ):

 instance ToJSON Tip where toJSON (Tip text created_at updated_at title category_id) = object ["text" .= text, "created_at" .= created_at, "updated_at" .= updated_at, "title" .= title, "category_id" .= category_id] 

This is almost correct, except that I also want a JSONify Tip id here ... but it is nowhere in the model! How can I do it? Is there a way to go from EntityVal to EntityKey ?

+4
source share
1 answer

An Entity is a combination of a key and a value. If you just have meaning, there is no general way to find out what it has. If it has any unique restrictions, you can use this to search for a key.

This EntityVal can theoretically be assigned different identifiers in different backend databases (which, perhaps, not all are of the same type). Or it could have been manually designed to be inserted, but has not yet been inserted, so it has not been assigned an identifier. The value Tip has no inherent identifier; it can only have an identifier in a specific database.

+2
source

All Articles