如何在 Kohana 3 中链接多个 ORM 关系?
我认为我在文档中找不到相当简单的问题的答案(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以收集数组中的关系:
PS。但似乎
song
和keyword
都必须位于$_belongs_to
属性中(一首song
有许多>连接
,一个连接
属于歌曲
)。You can collect relationships in arrays:
PS. But it seems like both
song
andkeyword
must be in a$_belongs_to
property (onesong
has manyconnections
, oneconnection
belongs tosong
).