Working on an old Kohana 2 project and I want to link two models.
I have a model called User with the following ORM relationships:
protected $primary_key = 'User_ID';
protected $belongs_to = array('group');
protected $has_many = array('user_address');
I have another Model called User_Address with ORM relationships:
protected $table_name = 'user_address';
protected $belongs_to = array('user');
However I am getting the following SQL error:
Unknown column 'user_address.user_User_ID' in 'where clause' - SELECT `user_address`.* FROM (`user_address`) WHERE `user_address`.`user_User_ID` = 2 ORDER BY `user_address`.`id` ASC
I can see from the error that it is trying to link to user_address.user_User_ID whereas it should be user_address.User_ID. Is there a way to map the foreign key like Kohana 3?
Got it!
Needed to add
protected $foreign_key = array('user_address' => 'User_ID');to the User_Model