如何在 Kohana 3 中链接多个 ORM 关系?

发布于 2024-10-13 22:39:09 字数 779 浏览 4 评论 0原文

我认为我在文档中找不到相当简单的问题的答案(http://kohanaframework.org /guide/orm/relationships

我需要一次定义与多个模型(粗体)(每个模型都有一个相应的表)的关系,如果这有意义的话。

我有几个模型,它们之间的关系稍微错综复杂。

连接模型$_belongs_to用户。这段代码运行得很好,非常棒。但连接还需要 $_has_one song (i can haz cheezeburger??),以及 $has_one keyword >,如果这是有道理的。

这是因为我想通过连接访问歌曲名称和关键字名称,例如使用$connection->song->name,然后 $connection->keyword->name...

所以,问题是我似乎无法链接上面详述的关系,因为我只能为每个模型声明一个关系....那么我该怎么做呢?或者也许还有另一种我不知道的更简单的方法......

我想我是一个n00b并且希望在这方面得到一些帮助。干杯。

fairly simple question I think that I couldn't find the answer to in the docs (http://kohanaframework.org/guide/orm/relationships)

I have the need to define relationships with several Models (in bold) (each has a corresponding table) at once, if that makes sense.

I have several models that have slightly intertwined relationships.

the connection model $_belongs_to the user. This code works fine, great. But the connection also needs to $_has_one song (i can haz cheezeburger??), and to $has_one keyword, if that makes sense.

This is because I want to access the song name and keyword name through the connection, for instance using $connection->song->name, and then $connection->keyword->name...

SO, the problem is I can't seem to chain the relationships detailed above, as I can only declare one relationship per model.... so how do I do this? Or maybe there's another much easier way of doing it that I'm unaware of...

I presume I'm being a n00b and would love some help on this. Cheers.

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

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

发布评论

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

评论(1

情定在深秋 2024-10-20 22:39:09

您可以收集数组中的关系:

class Model_Connection extends ORM {

   protected $_belongs_to = array(
      'user' => array(), 
   );

   protected $_has_one = array(
      'song' => array(),
      'keyword' => array(),
   );

}

PS。但似乎 songkeyword 都必须位于 $_belongs_to 属性中(一首 song 有许多 >连接,一个连接属于歌曲)。

You can collect relationships in arrays:

class Model_Connection extends ORM {

   protected $_belongs_to = array(
      'user' => array(), 
   );

   protected $_has_one = array(
      'song' => array(),
      'keyword' => array(),
   );

}

PS. But it seems like both song and keyword must be in a $_belongs_to property (one song has many connections, one connection belongs to song).

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