then in my user model, I have a property call gender, is it possible for me to create a gender relation with the params I created in config file? or is there any other way can do that because I dont want to create another table just have 2 records
public function relations()
{
return array(
'r_gender'=>array(self::BELONGS_TO, Yii::app()->params['gender'], 'gender'),
);
}
I would not create “Gender Model with 2 records”. I don’t see any good reason to create such a model.
[s]I don’t understand what you are trying to do with the STAT relation. Probably you have a wrong idea about it.
A user is either a male or a female. He or she can’t have a “male_count” or a “female_count”.
If you are thinking of a group of users … a group has many users, and a user belongs to a group … then you can think of a STAT relation on the group’s side, not on the user’s side.[/s]
[EDIT]
Ah, so you want to count the number of male and female in the users.
OK. Just count them. That’s all.
// User model
public static function getMaleCount()
{
return User::model()->count('gender = 1');
}
// or something like this.