Kohana ORM 关系

发布于 2024-11-28 23:15:00 字数 576 浏览 3 评论 0原文

我有几个表并为它们定义了关系。

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

一个部门可以有多个分支机构,一个分支机构只能属于一个部门。我需要能够获取部门名称、部门 ID、分支名称

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

{ protected $_belongs_to = array('部门' => array());

我还在数据库端创建了外键约束,并在删除时使用级联操作。这会导致问题吗?还是没关系?

I have a couple of tables and have defined relationships for them.

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

A Department can have more than one branch, a branch can only belong to one department. I need to be able to get the department name, departmentid, branchname

Branch has an instance of departmentid in it.

How do I pull this in one ORM call?

class Model_Admin_Departments extends ORM

{

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


class Model_Admin_Branches extends ORM

{
protected $_belongs_to = array('departments ' => array());

I have also created the foreign key constraints on the db side with action cascade on delete. Could this cause problems or that is fine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以可爱出名 2024-12-05 23:15:00

假设您拥有正确的声明的关系,您应该能够使用with(...) 方法

Assuming you have the right relationships declared you should be able to use the with(...) method on your ORM object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文