[英]Kohana ORM relationships $has_many and $belongs_to and foreign keys
在一個舊的Kohana 2項目上工作,我想鏈接兩個模型。
我有一個具有以下ORM關系的名為User的模型:
protected $primary_key = 'User_ID';
protected $belongs_to = array('group');
protected $has_many = array('user_address');
我還有一個名為ORM關系的User_Address模型:
protected $table_name = 'user_address';
protected $belongs_to = array('user');
但是我收到以下SQL錯誤:
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
從錯誤中可以看到它正在嘗試鏈接到user_address
。 user_User_ID
而應為user_address
。 User_ID
。 有沒有辦法像Kohana 3那樣映射外鍵?
得到它了!
需要添加protected $foreign_key = array('user_address' => 'User_ID');
到User_Model
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.