I need some help with this, please …
If I save a transaction status as a code in the db, but I want to translate them to meaningful names how do I do that? Is that even recommended? If no, what would be an alternative to that?
For example:
in the db the statuses are “S”, “P”, “A”
and in the actual application I’d like to display: “Submitted”, “Pending”, “Approved” accordingly.
Thank you!
Say for example you have a model called
Accountin which you are storing the transaction status in a column calledstatuswhose value will be ione of the codes that you have mentioned, you can doBy this way, your are overriding the method
statusprovided by activerecord onAccountobject.Depending on how you are going to use the
statusfield, you might be required to create proper index on those columns (for ex: if you are going to select accounts with pending transaction, etc)