php - Elements with common and separate properties in a database -
i have database table post
, user can submit many types of posts, , these types share properties, , have properties of own. e.x: both video , standard posts have description
, video posts have video link/file property.
what did creating table post containing common properties, creationdate
, description
.
and created other tables, containing other properties, , number of post types grows, think have add more tables.
of course, problem design when want retrieve 1 post, have retrieve data posts
table, use id
, type
retrieve data type table (ex : videos table). , when want retrieve data of different types in 1 page i'll have handle many tables.
which seems not practical since i'm working php/mysql in apache server.
is there other better idea can implement same result?
your design follows technique described in class-table-inheritance. there outline of technique in info tab.
you might want explore using shared-primary-key way speed things up, , way use post-id fk without having have different fk type each post type. speeds joins.
the down side have add new table whenever discover new post type. then, if building object model have add new subclass @ same discovery.
Comments
Post a Comment