I am not after the validation stuff, I need to do this in the model with some Active Record stuff.
In plain SQL would be
select distinct user.id from user as u
join user_details as ud on u.id=ud.user_id
join residence as r on r.id=ud.residence_id
where user.email=_EMAIL and r.zip_code=_ZIPCODE and r.occupent_no=_OCCUPANTS
As you are new to the forum I can presume that you are new even to Yii… so If you haven’t done so… first read the “Definitive guide to Yii” to get the basics… there is a section explaining relations… and a section explaining validation and validators…
Why do you think you are not after the validation stuff… as you wrote above… you have a form where a user can enter some data… that data should be validated so you need a validator… a custom one maybe that in turn will call a model function to check what you need…
If someone enters wrong details and there is no ID, I simple redirect them to a page that says: If you have provided valid details we have dispatched a new password to you.
I want to do the query in post #3.
For class `user`
public function relations() {
return array(
'residences' => array(self::MANY_MANY, 'residences', 'user_details(residence_id,user_id)'),
'details' => array(self::HAS_ONE, 'user_details',
'user_id'),
);
}
For class `user_details`
public function relations() {
return array(
'user' => array(self::BELONGS_TO, 'user', 'user_id'),
'residences' => array(self::HAS_ONE, 'residence',
'residence_id'),
);
}
For class `residence`
public function relations() {
return array(
'users' => array(self::MANY_MANY, 'user', 'user_details(residence_id,user_id)'),
'heating_type' => array(self::HAS_ONE, 'heating_type',
'heat_type_id'),
'irrigation_type' => array(self::HAS_ONE, 'irrigation_type',
'irrigation_type_id'),
);
}