[eluser]OverZealous[/eluser]
[quote author="Jinkusu" date="1253685933"]The issue is my table called User which has 4 diff models User, Lecturer, Guardian and Admin. Not only that the guardian has a many-to-one relationship with the user. How exactly do u set this up because i can set up a self relationship and a multiple relationship to same model but how do u go about doing a combination of the 2?[/quote]
@Jinkusu
The simplest solution, and I think the most flexible, is to have only one User model. Use flags (booleans or smallint values) to determine what type of user someone is.
I wouldn't bother having a different Class for each type of user. It will just make your life very difficult.
Then, set the self-relationship up like normal. Enforce the relationship in your code, not through complex models.
Code:
class User extends DataMapper {
var $has_one = array(
'guardian' => array(
'class' => 'user',
'other_field' => 'student'
)
);
var $has_many = array(
'student' => array(
'class' => 'user',
'other_field' => 'guardian'
)
);
}
Usage might be like this:
Code:
$guardian = new User();
$guardian->get_by_id($guardian_id);