1

I'm using Kohana Query Builder and trying do next:

$query
 ->join(«t1», «INNER»)
 ->on(«t1.id»,»=»,»t2.parent_id»)
 ->on(«t1.id»,»=»,»t3.x_id»)

This means:

INNER JOIN t1
ON(t1.id = t2.parent_id AND t1.id = t3.x_id)

But how force to use OR instead of AND of KO3 query builder join methods?

INNER JOIN t1
ON(t1.id = t2.parent_id OR t1.id = t3.x_id)
LINKeRxUA
  • 559
  • 6
  • 26
  • 1
    The [`Database_Query_Builder_Join`'s `compile()` method](http://kohanaframework.org/3.3/guide-api/Database_Query_Builder_Join#compile) seems to have `AND` hardcoded. So you either need to write/find your own Query_Builder or not use one at all I think – kero Feb 08 '15 at 10:53

1 Answers1

2

Due to Konaha source code all on() methods are concatinated with AND:

// Concat the conditions "... AND ..."
$sql .= ' ON ('.implode(' AND ', $conditions).')';

So you have at least 2 ways:

  • Redifine Database_Query_Builder_Join methods to support OR concatinator
  • (it's cheating) Use DB::expr() as 3rd parameter to on() method like:

    ->on('t1.id', '=', DB::expr('t2.parent_id OR t1.id = t3.x_id))

s.webbandit
  • 16,332
  • 16
  • 58
  • 82