Kohana 2 ORM:->with() for has_many 关系
我们有一个文章表和一个文章区域设置数据表。
class Article_Model extends ORM {
protected $has_many = array('article_translations');
[...]
class Article_Translation_Model extends ORM {
[...]
'articles_translations' 表包含 'article_id'、'locale_id'、'heading'、'body' 等列。
可以
SELECT article.id, article_translations.heading, article_translations.body
FROM articles
JOIN articles_translations ON (articles_translations.article_id = article.id)
WHERE articles_translations.locale_id = 'en_US.UTF-8'
使用 Kohana 2 ORM 吗?
->with() 结构仅适用于 has_one 关系。当然,articles_translations.article_id 和articles_translations.locale_id 是唯一的。
We have a table for articles, and a table for locale data for articles.
class Article_Model extends ORM {
protected $has_many = array('article_translations');
[...]
class Article_Translation_Model extends ORM {
[...]
'articles_translations' table contain 'article_id', 'locale_id', 'heading', 'body', etc. columns.
Is it possible to do
SELECT article.id, article_translations.heading, article_translations.body
FROM articles
JOIN articles_translations ON (articles_translations.article_id = article.id)
WHERE articles_translations.locale_id = 'en_US.UTF-8'
using Kohana 2 ORM?
The ->with() construction works only for has_one relations. The articles_translations.article_id and articles_translations.locale_id is UNIQUE, of course.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不过,您也可以采用其他方式:
然后您可以将文章列引用为:
You could go the other way though:
Then you can reference the article columns as: