Kohana 3 ORM compares 2 columns in the where section

I need to create a query like this:

SELECT * FROM `table1` WHERE `date1` < `date2`

I can not find how to compare 2 columns in kohan ORM. Here, date2 is considered text.

$foo = ORM::factory('model1')->where('date1','<','date2');

How can I write this line?

Thank!

Additional Information:

I am using this at 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']);
}
+5
source share
1 answer

If you do not want Kohana to modify the string, as it would with the third argument in the DB function, you can use a function DB::expr()that leaves what you pass unchanged. So in your example you can use

$foo = ORM::factory('model1')->where('date1','<',DB::expr('date2'));
+3
source

All Articles