我正在使用idiorm(https://github.com/j4mie/idiorm)开发一个应用程序,用于从数据库中获取数据。
这是我的代码:
$messages = Model::factory('Messages')->where('from_user_id','1')->find_many();
我想要包含where->('to_user_id','1')
如何在我的Idiorm查询中将其作为OR语句?
答案 0 :(得分:5)
这看起来就像手册告诉你要对OR条件做的那样
$messages = Model::factory('Messages')
->where_any_is(
array(
array('from_user_id' => 1),
array('to_user_id' => 1)
)
)
->find_many();
答案 1 :(得分:2)
我不熟悉idiorm,但是看source code你应该可以使用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))