There is a recurring problem regarding status fields and similar predefined set of values.
Let's take an example of an ordering system with an order entity which has a status that could be New, In Progress, Paid, etc.
The Status of an order need to be
How to do these three activities while keeping:
Here are some example implementations with their pros and cons:
Order table references the id of the status.
CREATE TABLE `status` (
`id` INT NOT NULL,
`name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`));
CREATE TABLE IF NOT EXISTS `order` (
`id` INT NOT NULL AUTOINCREMENT,
`status_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `order_status_idx` (`status` ASC),
CONSTRAINT `order_status_id`
FOREIGN KEY (`status_id`)
REFERENCES `status` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
The backend code has an enum that gives these predefined integers a meaning in the code
enum Status {
PAID = 7;
};
// While processing as action ...
order.status = Status::PAID;
The web service API will return the status number
order: { id: 1, status_id: 7 }
The frontend code has a similar enum that gives these predefined integers a meaning in the code. (like the backend code)
Pros:
status_id: 7
does not deliver a concrete meaning because it does not include the meaning of the status_id: 7
In database, the order table will contain a status columns with type ENUM containing the predefined statuses.
CREATE TABLE IF NOT EXISTS `order` (
`id` INT NOT NULL AUTOINCREMENT,
`status` ENUM('PAID') NULL,
PRIMARY KEY (`id`));
The backend code has constant values as code artifacts for the predefined status
enum Status {
PAID = 'PAID'
};
OR
class Status {
public:
static const string PAID = PAID;
};
To Be used as follwoing
// While processing as action ...
order.status = Status::PAID;
The web service API will return the status constant
order: { id: 1, status: 'PAID' }
The frontend code will have a similar construct for predefined status constants. (like the backend code)
Pros:
order
table.The database will contain a status table with one field called key
with type string which is the primary key of this table.
CREATE TABLE `status` (
`key` VARCHAR(45) NOT NULL,
PRIMARY KEY (`key`));
The order table will contain a field called status
with type string which references the key
field of the status
table.
CREATE TABLE IF NOT EXISTS `order` (
`id` INT NOT NULL AUTOINCREMENT,
`status` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`),
INDEX `order_status_idx` (`status` ASC),
CONSTRAINT `order_status`
FOREIGN KEY (`status`)
REFERENCES `status` (`key`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
The backend code has constant values as code artifacts for the predefined status
enum Status {
PAID = 'PAID'
};
OR
class Status {
public:
static const string PAID = PAID;
};
To Be used as follwoing
// While processing as action ...
order.status = Status::PAID;
The web service API will return the status constant
order: { id: 1, status: 'PAID' }
The frontend code will have a similar construct for predefined status constants. (like the backend code)
Pros:
Thank you.
When you’re faced with ethical dilemmas in nursing it’s best to refer to the foundation of patient care, consult your code of ethics, and speak with a professional, either at your place of employment or a trusted nurse mentor. Remember all ethical dilemmas you face only serve to make you a better, more caring,...
Just as the security dilemma may foster or amplify conflict among states that seek only security, so might a status dilemma create or amplify conflict among states that seek only to maintain their relative standing. Get access to the full version of this content by using one of the access options below.
An ethical dilemma (ethical paradox or moral dilemma) is a problem in the decision-making process. Corporate Strategy Corporate Strategy focuses on how to manage resources, risk and return across a firm, as opposed to looking at competitive advantages in business strategy.
When faced with ethical dilemmas nurses should first look to The Code for supportive information. Seek Ethics Education: For further guidance beyond The Code, look to mentors, supervisors, or even the nurse educators you know from nursing school. Sometimes speaking to someone regarding a moral dilemma can help you gain perspective.
This my approach for this problem:
status
with type string
in the orders
table.This makes adding a new status very easily by just editing your code base, and the retrieved value for the status is still a string (descriptive).
I hope this answer your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With