listData - only unique records?

Hello fellow Yii fans!

Assume i have a table ‘users’ and a table ‘event_participants’, I have a default user (when there are not enough participants in an event), that ’ default user’ can be added more than once. Now, i want to get a list of all paricipants (including all the ‘default users’)

I did this:

$list = CHtml::listData(eventParticipants::model()->with('user')->together()->findAllByAttributes(array('eventId'=>$event->Id)),userId,user.username); 

Assuming I’ve got 2 default users in an event: this solution is only returing one of the two default users, but the 2 ‘default users’ have to be returned!

Can anyone provide a solution?


Hey klavan!

If i understood correctly, you have a table un your DB with events and another one with users. Events need a minimum (which i assume varies according to the event, right?) and in case the amount of users doesn’t reach that minimum, you add as many default users as necessary. I see your users table has an field called eventID: a user can only participate in one event?

Im asking these questions to further understand your problem. Because what i understand so far is that you’ve got a table users and you add “default users” (an autoincremented pk?) to reach the minimum amount necessary of participants. If this is so, I would strongly suggest to handle this another way, instead of making an impact on the DB resolve it programatically.