表未加入 Kohana 3.1 ORM

发布于 2024-11-01 21:25:38 字数 533 浏览 5 评论 0原文

我该如何让它发挥作用?

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

我已经设置了所有关系,当我执行其他查询时,一切似乎都正常。但是,在上面的查询中,它没有将表 users 连接到 mytable。我认为这可能是因为一个 mytable 可以有很多用户。

在参考文献中,有一种名为 join() 的方法,我想我可能需要在这里使用它,但他们没有提供任何相关信息,而且我在这里搜索的内容不起作用。

当我尝试使用 join 而不是 with 时,它会尝试加入表,但它不包含任何“加入”信息,只给出一个空的 ()

我知道我的 ORM DB 关系都设置正确,所以我有点困惑。

How do I get this to work?

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

I've got all of my relationships set up and everything seems to be working when I do other queries. However, in the query above it is not joining table users to mytable. I think it may be because there can be many users for one mytable.

In the reference there is a method called join() which I think I might need to use here, but they don't give any information on it, and the stuff I've searched for on here does not work.

When I try to use join instead of with, it tries to join the table, but it doesn't include any "join on" information, just gives an empty ().

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

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

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

发布评论

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

评论(2

深海夜未眠 2024-11-08 21:25:38

Kohana 有不错的文档,没有在正确的位置查找......好吧,你的问题。

ORM::with() 用于加载一对一(属于并具有一个)关系,尽管您拥有所有 Database_Query_Builder 与 ORM 一起使用的方法可供您使用:

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

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();
游魂 2024-11-08 21:25:38
SELECT * from table1
LEFT JOIN table2
ON table1.id = table2.id
AND table2.flag = 'Y' 
AND table2.siteid = '12'
WHERE table1.siteid = '12'

上面的查询是如何用kohana的ORM格式编写的?下面的一项是否正确

$stuff = ORM::factory('table1')
    ->join('table2','LEFT')
    ->on('table1.id','=','table2.id')
    ->on('table2.flag','=','Y')
    ->on('table2.siteid', '=', '12')
    ->where('table1.id', '=', '12')
    ->find_all();
SELECT * from table1
LEFT JOIN table2
ON table1.id = table2.id
AND table2.flag = 'Y' 
AND table2.siteid = '12'
WHERE table1.siteid = '12'

How the above query is written in ORM format of kohana? Is the below one is correct

$stuff = ORM::factory('table1')
    ->join('table2','LEFT')
    ->on('table1.id','=','table2.id')
    ->on('table2.flag','=','Y')
    ->on('table2.siteid', '=', '12')
    ->where('table1.id', '=', '12')
    ->find_all();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文