2

我正在使用 idiorm ( https://github.com/j4mie/idiorm ) 开发一个应用程序,用于从数据库中获取数据。

这是我的一段代码:

$messages = Model::factory('Messages')->where('from_user_id','1')->find_many();

我想包含一个 or 声明where->('to_user_id','1')

如何在 Idiorm 查询中将此作为 OR 语句?

4

2 回答 2

5

这看起来像手册告诉您为 OR 条件做的事情

$messages = Model::factory('Messages')
                   ->where_any_is(
                                  array(
                                         array('from_user_id' => 1),
                                         array('to_user_id' => 1)
                                       )
                                  )    
                   ->find_many();
于 2016-05-18T19:26:19.413 回答
2

我不熟悉 idiorm,但查看源代码应该可以where_raw用来构建自己的 where 子句:

    /**
     * Add a raw WHERE clause to the query. The clause should
     * contain question mark placeholders, which will be bound
     * to the parameters supplied in the second argument.
     */
    public function where_raw($clause, $parameters=array()) {
        return $this->_add_where($clause, $parameters);
    }

就像是->where_raw('from_user_id = ? OR to_user_id = ?', array(1, 1))

于 2016-05-18T19:23:01.663 回答