How do I approach showing and hiding specific data fields from view when using database-modeling approach?

48
September 21, 2018, at 2:50 PM

In my use case I have a Pump product with several fields, like model, min_flow, max_flow, active, etc.

I want to have ability to display those fields to the user and give them the ability to edit values of those fields. In addition to this, I want administrator users to have ability to show or hide those fields for users.

My question is about how to model my database to allow for showing and hiding of fields. Namely, I need a way to encode fields I want to show, and those I want to hide. I also want to let users define their own names for the fields.

Currently I have this:

CREATE TABLE `pump` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `model` CHAR(11),
  `min_flow` float,
  `max_flow` float,
  `active` tinyint(1),
  PRIMARY KEY (`id`)
);

One way I can think of encoding names and show/hide flag is like so using MySQL's COMMENT metadata field, where the COMMENT field contains the name and the show/hide flag separated by a | separator:

CREATE TABLE `pump` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `model` CHAR(11) COMMENT 'Model|1',
  `min_flow` float COMMENT 'Min Flow|1',
  `max_flow` float COMMENT 'Max Flow|1',
  `active` tinyint(1) COMMENT 'Active|0',
  PRIMARY KEY (`id`)
);

I can then read the metadata and show/hide fields accordingly and also display the field name in the process.

Is that an acceptable way to do this, or is there a better way?

READ ALSO
Making java Entity classes from MySQL tables in netbenas

Making java Entity classes from MySQL tables in netbenas

I have a MySQL database, with some data, that I want to be transformed into java Entity classesI have my Persistence

25
Aurora serverless not connecting from CLI and mysql workbrench

Aurora serverless not connecting from CLI and mysql workbrench

I make a Aurora serverless cluster and trying to connect it from command line using command

32
Adding new values to mysql database no longer possible?

Adding new values to mysql database no longer possible?

Hi guys please consider the code belowI was using it to add new values to my table(booking) in mysql database(seat_booking)

19
How Sequence Matters in Laravel query builder for mysql

How Sequence Matters in Laravel query builder for mysql

The complied query has different sequence from the codeThe query works but I don't know why it works!

44