表未加入Kohana 3.1 ORM [英] Tables not joining in Kohana 3.1 ORM

查看:108
本文介绍了表未加入Kohana 3.1 ORM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使它工作?

$stuff = ORM::factory('mytable')
    ->with('user')
    ->with('other_stuff')
    ->find_all();

我已经建立了我的所有关系,并且当我执行其他查询时一切似乎都正常.但是,在上面的查询中,它没有将表 users mytable 联接在一起.我认为可能是因为一个 mytable

可能有很多用户.

在参考文献中,有一种名为join()的方法,我认为我可能需要在其中使用它,但是它们没有提供有关 任何 的信息,并且我在此处搜索的内容无法正常工作.

当我尝试使用join而不是with时,它将尝试联接表,但是它不包含任何"join on"信息,只给出一个空的().

我知道我的ORM数据库关系均已正确设置,所以我有些困惑.

解决方案

科哈纳(Kohana)有不错的文档,如果在不正确的地方查看是...好,您的问题.

尽管您拥有所有().

I know my ORM DB relationships are all set up correctly, so I'm a bit baffled.

解决方案

Kohana has decent documentation, not looking in the right place is ... well, your problem.

ORM::with() is used for loading one-to-one (belongs to and has one) relations, though you have all the Database_Query_Builder methods to use with ORM on your disposal:

$stuff = ORM::factory('mytable')
        ->join('users','LEFT')
        ->on('users.mytable_id','=','mytables.id')
        ->find_all();

这篇关于表未加入Kohana 3.1 ORM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆