【问题标题】:Addressing related tables in Kohana's ORM where method在 Kohana 的 ORM where 方法中寻址相关表
【发布时间】:2011-12-02 10:21:52
【问题描述】:

您如何将以下 SQL 查询表示为 Kohana 的 ORM 请求,更具体地说是 where 子句?

SELECT items.* 
FROM items 
LEFT JOIN users ON items.user = users.id
WHERE users.name = 'john.doe'

【问题讨论】:

    标签: php sql orm kohana


    【解决方案1】:
    ORM::factory('item')->join('users', 'LEFT')->on('item.user', '=', 'users.id')->where('users.name', '=', 'john.doe')->find_all();
    

    这将产生以下查询:

    SELECT item.* FROM items LEFT JOIN users ON item.user = users.id WHERE users.name = 'john.doe'
    

    记住要遵循 Kohana 命名约定(即数据库名称应该是复数 (users) 但模型应该是单数 (Model_User))。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多