"Add to list" functionality

I need to implement a simple functionality whereby agents can add members to a list of favourites. The way I believe this needs to be done is by having a table called ‘favourites’ with fields:




Now I have the following questions:

  1. Do we still need the ‘id’ field for this to work in Yii/CGridView?

  2. What is the best way to get the total number of agents that a member has been favourited by? Should we store a value in the member record and update it each time a agent adds/removes the member from their favourites list? Or should we perform a count() query on the favourites table each time we need to know the value?

  3. How can this be extended so that agents can add members to different favourite lists? A member can be part of multiple lists.

  1. Use a CStatRelation within your relations array for the Agent model:

'num_favorited' => array( self::STAT, 'favourites', 'agent_id')

This will enable you to pull in the appropriate count by simply referencing 


  1. Add a list ID to your favourites table, which would reference a lists table having ID and ‘Name’