Greetings,
I have a form which it has almost 150 checkbox, but they are not in one place, the form is divided into divisions and each division has blocks, the checkboxes are put in these blocks depending on their group
where you can find four checkbox in this place and eight in other and 30 in some other and so go on.
So I made a two table’s one to store the groups and other to store checkboxes and to which group they belong to.
FormBlocks
--------------------------
| ID | key |
--------------------------
| 1 | property_type |
| 2 | providors |
--------------------------
BlocksCheckBoxes
------------------------------------------------
| ID | Label | Key | FormBlockId |
------------------------------------------------
| 1 | Sweet Home | home | 1 |
| 2 | Farm | farm | 1 |
| 3 | Invst Bank | bank | 2 |
| 4 | Constructor | constr | 2 |
------------------------------------------------
I have two approaches to store their values:
The first one store the checkbox values as concatenated string of their keys and insert it directly to the designated table, eg:
UserProperties
----------------------------------------
| ID | Customer | PropertiesType |
----------------------------------------
| 1 | Cat | home,farm |
----------------------------------------
pros:Very easy to implement and all I need is just to add a column and you are ready to go, and theoretically it is faster
cons: Will lose db level of data integrity and it will depend on the application level (I think I can live that)
The second way I create tables for each block, eg:
UserProperties
---------------------
| ID | Customer |
---------------------
| 1 | Cat |
---------------------
UserPropertiesTypes
--------------------------------------
| ID | CustomerId | CheckBoxId |
--------------------------------------
| 1 | 1 | 1 |
--------------------------------------
| 1 | 1 | 2 |
--------------------------------------
pros: I see it as the professional way and will insure the data integrity at db level
cons: I need to create table for each part that has checkbox group which is a headache in development specially if you have many groups in the form.
I didn't consider bitwise because I will have to create a column for each checkbox and I see it is not efficient for big groups who will have more than 30 checkbox. so I preferred to make a way that will be implemented in the application
If you have any suggestions or better way to do it please don’t hesitate to tell.
Thank you very much