Multiple Relations Between Two Tables In Yii

hi

I have two tables, User and Post. My required set up is as under :

A User can make Posts

A User can reply a Post.

A user can add a Post to his To DO List

A user Can follow a Post (to get notification when some one update/reply a post)

A notification tables to store notification e.g UserID,PostId,Notification_status etc (As in facebook notifications)

Now as we can see that multiple relations are required between User and Post tables, How can i Implement this in Yii, as for as mySql is concerned, i think i need to have a separate table for each relation. eg one table "Followers" having field UserId,PostID etc another tables "TODOs" having fields "postID , UserID etc and so on

is this the correct method or some other better alternate? how to define these things in Rletation Method in Yii Models?

Thank and Regards

You need to define rules in your model class.For e.g

A user can make many posts .The relation in the User class will be as follows.:

public function relation()

{

return array(

‘posts’=>array(self::HAS_MANY,‘POSTS’,post_id);

);

}

And then you can access comments in the view as $data->posts->postname;

where dataProvider is of User Model class.

A User can make Posts

A User can reply a Post.

A user can add a Post to his To DO List

A user Can follow a Post (to get notification when some one update/reply a post)

A notification tables to store notification e.g UserID,PostId,Notification_status etc (As in facebook notifications)

Now as we can see that multiple relations are required between User and Post tables, How can i Implement this in Yii, as for as mySql is concerned, i think i need to have a separate table for each relation. eg one table "Followers" having field UserId,PostID etc another tables "TODOs" having fields "postID , UserID etc and so on

is this the correct method or some other better alternate? how to define these things in Rletation Method in Yii Models?

Thank and Regards

[/quote]

This will be same as connecting one table to other i.e. Building one relation between tables.

You can see that relations are in the form of array, means a table can have any number of relations…

Thanks

I am re-posting with more details ::

A Post Belongs to a User.

A Post may be addressed to one or Many Users

Users can follow a Post to receive notification when there is some reply/comment on a post.

A User can add a Post to his ToDo list and when he completes this ToDo he can mark this ToDo Done (so this ToDo be removed from his ToDo list)

Users Should get notification when a post is addressed to a User, or when some reply/comment is given on Post the User is Following. (A user who create the Post , or A user who is addressed in Post, will be automatically following that Post).

So This way i need to create different many many relations ships between Post and User tables, so do i Need to create a different joining table for each relation? like Post_user_follower(id,PostId,UserId) to save the data of Users who are following some Post, and so on for each relation, is this a normal case or there will be circular joins creating infinite loops?

can i save additional data in the joins tables along with the Id’s of joining tables e.g for ToDO’s, i will create a table Pots_user_toDo (id,userId,PostId,toDo_status) so that i can save the status of ToDO in the join table to check whether the ToDO is pending or completed, or i need to save the ToDo_status in another tables e.g ToDo(id,toDO_status)