It's the first time here so I don't know if it's the right place to ask.. I'm not good in database design, just learning, so I'd like some advice if possible.
The case:
I'm building a really small application, a plugin, who's tables will likely have not too much records in real life (less than 50 in extreme situations), so performance is not crucial.
-
The user can create n Groups. A Group should have a 'hook' field.
-
For each Group, the user can create n BannerBoxes. So, a Group can have many BannerBoxes, a BannerBox can have only one group. Therefore a 1-many relation.
-
There can be n languages, and the Language table is already in place and has id_lang field. The language-group relation is 1 (language)-many (groups)
I'll often have to ask the db for all BannerBoxes saved for a certain language, grouped by Group. So, first find all Groups of a language, then for each Group, find its BanneBoxes.
I've thought about 2 solutions, but I cannot decide which could be better, and since I'm definitly a newbe, both could be just wrong.
a. Group entity with [hook, id_lang] fields; BannerBox entity with an [hook] field (desides the others). So when selecting, I can join the Group table with Language table on id_lang and then join with BannerBoxes on hook field.
b. Only the BannerBox entity, in this case with both [hook, id_lang] fields. I could join with Language by id_lang and then group by hook.
I also guess that a Group_BannerBox table [id_group, id_bannerbox] would be useless since I think it's a solution for many-many relations, am I right?
So, what would you do? a. or b.?
Thank you!
Best Answer
User
table with aUserId
PK and any other user related fields.Language
with aLanguageId
PK and the name of the language.Group
table with aGroupId
PK,UserId
FK,LanguageId
FK, Hook? and any group specific fields.BannerBox
table with aBannerBoxId
PK,GroupId
FK, and any other Banner Box specific fieldsThis will let you get all the information you need assuming that languages are consistent for a group.
I don't know what your Hook field is so answering @ypercube's comment would be helpful. In this answer I assumed it was some sort of business logic that was relevant at the group level.