key_field not working on custom has_many

edited May 2017 in Modules
Hospital_model
protected $key_field = 'hospital_id';

Doctors_model
public $has_many = array(
'hospitals' => array('hospitals_model'),
);

error
Unknown column 'slmc_hospitals.id' in 'where clause'

SELECT `slmc_hospitals`.* FROM `slmc_hospitals` WHERE `slmc_hospitals`.`id` IN(2) AND `slmc_hospitals`.`published` = 'yes'

What is wrong in my code, thank you.

Comments

  • edited 7:23AM
    It looks like by the error message that there is no "id" field in your "slmc_hospitals" table.
  • edited 7:23AM
    Oh i see, I thought when you add $key_field, that will be used instead of 'id'.
Sign In or Register to comment.