My CMS Application which lets users to post Classifieds, Articles, Events, Directories, Properties etc has its database designed as follows :
1st Approach:
Each Section (i.e 'classifieds','events' etc) has three tables dedicated to store data relevant to it:
Classified:
- classified-post
- classified-category
- classified-post-category
Event:
- events_post.
- events_category.
- events_post-category.
The same applies for Articles, Properties, Directories
etc. each Section has three tables dedicated to its posts, categories.
The problem with this approach is:
- Too many database table. (which leads to increasing number of model, controller files)
- Two Foreign Key's to avoid duplicate entries in associative tables.
For example:
Lets say tablecomments, ratings, images
belongs toclassified-post
,events-posts
etc, so the structure of the tables would be:
Image[id, post_id, section]
The second FK section must be stored and associated to avoid duplicate posts.
2nd Approach:
This approach will have single posts table which has section column associated to each posts as foreign key. i.e
post: id, section, title etc
....VALUES ( 1, 'classifieds','abc') (2,'events','asd')
While the second approach is little bit cumbersome when doing sql queries, it eases up the process when performing relational table queries. ex: table images, ratings, comments belongs to posts table.
image [ id, post_id (FK) ]
While this approach seems clean and easy, this will end up in having oodles of columns in posts table, that it will have columns related to events, classifieds, directories etc which will lead to performance issues while querying for rows and columns.
The same applies for categories. It could be either one of the two approach, either save section column as second foreign key or have separate tables for each sections ( 1st approach ).
So now my question is, which approach is considered to be better than the other? does any of the two approaches have benefit over the other in performance wise? or what is the best approach to tackle while dealing with these paradigms?