Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 178125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:10:35+00:00 2026-05-11T14:10:35+00:00

Say you have a ‘post’ object in a typical blog scenario. A blog post

  • 0

Say you have a ‘post’ object in a typical blog scenario. A blog post can have different statuses like ‘draft’, ‘published’, ‘approved’, et cetera. What are the best ways to handle this, specifically regarding storing this data in the database in a meaningful way as well as in a meaningful way in code.

Generally I’ve seen these stored as an int associated with a row in the database (of the ‘posts’ table in this example). Sometimes there’s a lookup table in the database to explain these statuses (i.e. status table with id=>1 name=>draft, etc.). Normally, I’d translate these into an enum in the Data Access Layer to have a more meaningful code representation and to avoid having ‘magic numbers’.

However, this solution has a developer updating two different places (database and code) to add or change a status type.

What’s a better way to do this? This seems to be a type of problem I’ve run into frequently but I’ve never seen a good way to handle it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:10:36+00:00Added an answer on May 11, 2026 at 2:10 pm

    I like setting a status_id and creating a lookup table with the statuses in it and a corrresponding enum as you suggested.

    If my statuses are essentially immutable (e.g. state of a blog post, state of an order, etc.), I will create a unit test that determines if the number of enums I use matches the data in the lookup table – so if someone were to add a status to the database in the future it would fail the test, telling the developer to add to the enum.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say I have a class named Frog, it looks like: public class Frog {
Say I have a SqlAlchemy model something like this: from sqlalchemy.ext.declarative import declarative_base from
say I have input data like so: firstName | lastName | Country Bob |
Say I have a LINQ-to-XML query that generates an anonymous type like this: var
say i have the 3 non blocking sends like this MPI_Isend (); MPI_Isend ();
Say I have the following code: private Integer number; private final Object numberLock =
Say I have an Intent like this: Intent intent = new Intent(context, MyActivity.class); I
Say I have a site like stackoverflow. I need to add a search functionality,
let say have element like this <div class=watch-me style=display: none;>Watch Me Please</div> as we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.