TextColumn depending on database value....
Should be a simple one. I have a database table column "status".. that statuses are encoded as 1,2,3,4,5 and stored as an int.
On the Form used to create the table row, I have a Select:: thus:
...and this works. I render the page, hit the drop down, I see the options "Open", "Closed" etc but it's the number 1, 2, 3 etc goes in the database. Great!
My issue is then how do I display that on the table? I can't find a code snippet to plagiarise to do this! How do I display "Open", "Closed" etc depending on 1, 2, 3 etc in the database?
TIA!
5 Replies
Solution
I'd use mutators/accessors to centralise that transformation
Use Enums
looking into both these (thanks). If I'm right, using enums will hardcode the text into the db. I want to be able to change the text down the road. Looks like mutators/accessors is the 'proper' way to do it, looking for a relevant example now π
you can still use non string backed enums and just cast it on the model.
Thanks for the pointers, got it working through accessors π