In Laravel 4.2 there is a bug that when you perform a union on queries that have bindings in the joins, the join bindings do not get merged. 4.2 not being supported, they won't accept/fix this. I've gone through the Builder and Grammar and I'm not finding where the problem is. I will be doing a lot of queries with unions that contain joins so I would like to fix this in my framework instead of working around this. Anyone able to help me identify how to fix this in the Builder or Grammar?
Example code: https://paste.laravel.io/r5VQ1
public function test2()
{
$param1 = 1;
$param2 = 2;
$tableA = \DB::table('childA')
->select(['*'])
->leftJoin('inventory', function($join) use ($param1) {
$join->where('inventory.tenantId', '=', $param1);
});
$tableB = \DB::table('childB')
->select(['*'])
->leftJoin('inventory', function($join) use ($param2) {
$join->where('inventory.tenantId', '=', $param2);
});
$tableA->union($tableB)
->orderBy('code');
$sql = $tableA->toSql();
$bindings = $tableA->getBindings();
$this->assertEquals(array(1, 2), $bindings);
// $bindings = array(1), should be array(1, 2)
}
via user3720435