我正在使用idiorm开发一个应用程序(https://github.com/j4mie/idiorm)用于从数据库中获取数据。
这是我的代码:
$messages = Model::factory('Messages')->where('from_user_id','1')->find_many();
我想包括一个或声明where->('to_user_id','1')
如何在Idiorm查询中将其作为OR语句?
这看起来像是手册告诉您对OR条件所做的操作
$messages = Model::factory('Messages')
->where_any_is(
array(
array('from_user_id' => 1),
array('to_user_id' => 1)
)
)
->find_many();
我不熟悉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))
的东西