Models Structure

Hello! I have a bit complicated data structure in my project and I’m not sure what is the best approach to work with it in Yii application. I know it’s ambigious question, any thoughts would be appreciated.

I have several data types - article, photo post, audio, video and so on (like in Tumblr). Additionally, posts could be added to personal blog OR public community. Posts have some common fields (like title) and some unique, different for every data type. At the moment I have such schema:

posts

—————

id

title

blog_or_public_flag

video_posts

—————

id

url

post_id

photo_posts

—————

id

photo_id

post_id

And such models:

Post

PublicPost extends Post

CommunityPost extends Post

VideoPost

PhotoPost

Post model has relations for each data type. When working with post, for example in a view, i access common fields like $post->title and datatype-unique like $post->video->url.

Is there way to optimise this structure, make it more stable and convenient to use?

Seems like you are doing fine as it is. Just make sure all your tables are normalized and their relationships are well defined.