2011-08-10 38 views
0

我有幾個表併爲它們定義了關係。Kohana ORM關係

{Table Department} {Table Unit} {Table Branch} 

一個部門可以有多個分支,一個分支只能屬於一個部門。我需要能夠得到部門名稱,出發地,branchname

Branch has an instance of departmentid in it. 

如何在一次ORM呼叫中接受此操作?

class Model_Admin_Departments extends ORM 

{

protected $_has_many = array('branches' => array()); 


class Model_Admin_Branches extends ORM 

{ 保護$ _belongs_to =陣列( '部門'=>數組());

我也創建了數據庫端的外鍵約束與行動級聯刪除。這可能會導致問題或者這很好嗎?

回答

0

假設你有權利relationships declared你應該可以在你的ORM對象上使用with(...) method

+0

我收到未定義的索引:division_id。看看我的代碼示例在新的編輯。 – Churchill

+0

我得到了問題。我需要在關係聲明中聲明外鍵以使其工作。默認是尋找'declarationname_id'這個鏈接節省了我很多:http://kohanaframework.blogspot.com/2010/12/kohana-3-orm-relationships.html – Churchill