Kohana 3 ORM 比较 where 子句中的 2 列
我需要生成这样的查询:
SELECT * FROM `table1` WHERE `date1` < `date2`
我找不到如何比较 kohana ORM 中的两列。这里 date2 被视为文本。
$foo = ORM::factory('model1')->where('date1','<','date2');
我该如何写这一行?
谢谢!
更多信息:
我暂时使用这个:
$query = DB::query(Database::SELECT, "SELECT id FROM table1 WHERE `date1` < `date2`");
$result = $query->execute();
$foo = array();
foreach ($result as $r) {
$foo[] = ORM::factory("model1", $r['id']);
}
I need to generate query like that :
SELECT * FROM `table1` WHERE `date1` < `date2`
I can't find how to compare 2 columns in kohana ORM. Here date2 is considered as text.
$foo = ORM::factory('model1')->where('date1','<','date2');
How can I write this line ?
Thanks!
More info:
I use this for the moment:
$query = DB::query(Database::SELECT, "SELECT id FROM table1 WHERE `date1` < `date2`");
$result = $query->execute();
$foo = array();
foreach ($result as $r) {
$foo[] = ORM::factory("model1", $r['id']);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不希望 Kohana 修改字符串,就像 DB where 函数中的第三个参数一样,您可以使用
DB::expr()
函数,该函数将使您传递的内容保持不变。因此,根据您的示例,您可以使用If you don't want Kohana to modify the string, as it would with the 3rd argument in the DB where function, you can use the
DB::expr()
function which will leave what you pass unmodified. So with your example, you could use