Belongs_To Relation Returns Not All Results

I have two model.

User model BELONGS_TO Group model and in the Users` model I have set

	public function relations()


		return array(

            'group'=>array(self::BELONGS_TO, 'Group', '', 'on' => '`t`.`group`=`group`.`name` AND `group`.`created` < `t`.`created`', 'order'=>'`group`.`created` DESC'),



Here is why I do it this way: The groups table is populated periodically from external software. Group fields are: id, name, created. When there is a new group it is added with new id and current time. Each User is related to a group depending on the time user was created.

Right now the relation I am using is working, and it is connecting the tables values properly, BUT when there are more Groups created with the same name, the results displayed are limited.

For example if I have Group named "Test group", and create one more group with the same name the CGridView that shows my Users will be one less. If I create 2 more - the User results will be two less.

What are my options to resolve this?

I’m a little confused as to what you are trying to accomplish. Anyway:

Table relations are from a link field of one table to the pk of the other ‘User.group_id’ to ‘’.

Is unique? An SQL GROUP ON might work but be advised ‘Test group’ is different from ‘Test Group’, from 'Test group ', etc, etc, etc.

Is there a HAS_MANY relation in Group? Every relation example I have seen has a relation set in the Models of each involved table. User=>BELONGS_TO Group, Group=>HAS_MANY User.