hi,
I'm making my first CakePHP project (apart from all the tutorials I did...).
I'm making a site for trainers and athletes in the athletics sport.
now in my database I have a user table with fields: id, username, firstname, lastname, email, password, ...
then I have 2 other tables with the fields:
trainers: id, type_id(sprint, distance, throwing, ...), user_id
athletes: id, type_id(sprint, distance, throwing, ...), user_id, trainer_id
my trainer model looks like this
<?php
class Trainer extends AppModel {
var $name = 'Trainer';
var $hasOne = array('User');
var $hasMany = array(
'Schema'=>array(
'className'=>'Schema',
'foreighnKey'=>'trainer_id'
),
'Athlete'=>array(
'className'=>'Athlete',
'foreighnKey'=>'trainer_id'
)
);
}
?>
my Athlete model looks like this
<?php
class Athlete extends AppModel {
var $name = 'Athlete';
var $hasOne = array('User');
var $belongsTo = array(
'Trainer'=>array(
'className'=>'Trainer',
'foreighnKey'=>'trainer_id'
),
'Schema'=>array(
'className'=>'Schema',
'foreighnKey'=>'schema_id'
)
);
}
?>
my user model is currently like this
<?php
class User extends AppModel {
var $name = 'User';
var $belongsTo = array('Usertype');
}
?>
but that should obviously change, because when I go to domain/app/trainers or domain/app/athletes I get the error:
Warning (512): SQL Error: 1054: Unknown column 'User.trainer_id' or 'User.athlete_id' in 'on clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 681]
so short recapitulation: a user is either a trainer or an athlete, and I have a users table, an athletes table and a trainers table.
an athlete has one trainer and one schema a trainer has many athletes and many schemas...
the problem lies with a user being a trainer or an athlete..., what do I have to put in my models to make this work? I hope I made this clear enough :s