Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySql – need help modeling database

I’m currently working on a mobile application.

The principle is simple, a user can add a marker on a map.
The marker belongs to a category and each category has different fields.

Example :
A user adds a marker on the map, chooses the category (point of interest) then fills in the necessary information for the point of interest (Title, Description, Type).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If he wants to report an obstacle, the fields will be different (type, description)

Here is how I modeled this

My modeling

the problem is that each marker will necessarily have 2 null fields.

Do you think my modeling is consistent? If not, do you have an idea for a solution?

>Solution :

I think that you would need following tables.

markers (id, name, latitude, category_id)
categories (id, name) 
fields (id, category_id, name)
values (id, marker_id, field_id, value)

Because each marker have one category.
Each category have many fields.
Each value has 2 foreign keys because each marker has his own fields, so we need also values for them.

markers

id name category_id
1 new-york 7

categories

id name
7 POI

fields

id name category_id
1 Title 7
2 Description 7
3 Type 7

values

id marker_id field_id value
1 1 1 title of
2 1 2 this is description for the marker new-york
3 1 3 regular
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading