I feel pretty darn dumb posting this question, but im completely baffled (probably because im quite new to cake and a bit intimidated)..
hasOne hasOne
donors | blood_groups | donor_types
Att ------------------+-----------------------+---------------------+
DonorID (pk) | blood_group_id (pk) | type_id (pk) |
Name | group | type |
Surname | | |
type_id(fk) | | |
blood_group_id(fk)| | |
The Donor Model
class Donor extends AppModel{
public $hasOne = array(
'BloodGroup'=> array(
'className' => 'BloodGroup'
),
'DonorType' => array(
'className' => 'DonorType'
)
);
I am already using the assoctiated models to populate a an FormHelper input in the donor registration view, all is good.
However when I try to retrieve a donor record this error occurs
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BloodGroup.donor_id' in 'on clause'
This ofcours means that cakePHP is looking for the fk donor_id inside blood_groups table. However the relationship is the other way around and the fk is stored within donors table.
I do not know whether the db design is flawed or if the association needs to be redefined within cake. please help, as I am quite new to cakePHP and I a practically forced to use it because of its merits. I have read all the section about Association between models in the cake doc, but I am still struggling. How can I go about this?