I want to get two queues into one.
$buildings_queue=IngameBuildingQueue::where(DB::raw('UNIX_TIMESTAMP(`start_time` + `duration`)'),'<=',time());
$recruit_queue=IngameRecruitQueue::where(DB::raw('UNIX_TIMESTAMP(`start_time` + `duration`)'),'<=',time());
$queue=$buildings_queue->unionAll($recruit_queue);
dd($queue->toSql());
Laravel throw:
[ErrorException] Undefined property: Illuminate\Database\Eloquent\Builder::$bindings
but when I delete where() methods everything works fine.
How can I fix it?
What version please.
Latest, 5.1
Reproducible in 02180b9b6f6d7fb6d2ccc5552ffc174cec4ce993.
Undefined property: Illuminate\Database\Eloquent\Builder::$bindings
/Illuminate/Database/Query/Builder.php:1249
/Illuminate/Database/Query/Builder.php:1262
/Illuminate/Database/Eloquent/Builder.php:943
Tested code:
$builder = new Illuminate\Database\Eloquent\Builder(new Illuminate\Database\Query\Builder(
m::mock('Illuminate\Database\ConnectionInterface'),
m::mock('Illuminate\Database\Query\Grammars\Grammar'),
m::mock('Illuminate\Database\Query\Processors\Processor')
));
$builder->unionAll($builder);
Note: it's a very simplified test case when error can occur.
The problem is that Database\Query\Builder::union expects a Database\Query\Builder as first param. But in this case, Database\Eloquent\Builder is passed. The Eloquent Builder don't have the $bindings attribute so it'll fail.
So my doubt is: this should be allowed? If yes, is very easy to fix it, just check if first param is a Eloquent Build and getQuery() from it. Fixed. I guess that is valid this idea, but...
Is possible to fix it basically by doing exactly what I said, directly on user code:
$queue=$buildings_queue->unionAll($recruit_queue); // before, failing
$queue=$buildings_queue->unionAll($recruit_queue->getQuery()); // after, fixed
Thanks @rentalhost - it's working! Thank You.
I don't now if it should works natively. Can you reopen just for expect another opinion?
Okay I reopen it
https://github.com/laravel/framework/pull/10477 has just been merged and should fix this issue (when a new release is tagged).
$spl_invitees=DB::table('ec_meeting_special_invitees')
->select('meeting_id')->get();
$meeting=DB::table('ec_meeting_master')
->whereNOTIn('meeting_id',function($query){
$query->select('meeting_id')->from('ec_meeting_status_updation')
->where('status_id',2);
})
->whereNOTIn('meeting_id',function($query) use($spl_invitees){
$query->select('meeting_id')->from('ec_invited_members')
->union($spl_invitees)
->get();
})
for this i am getting error
in Macroable.php (line 74)
聽
Never mind. It was an issue on my end.
Most helpful comment
The problem is that
Database\Query\Builder::unionexpects aDatabase\Query\Builderas first param. But in this case,Database\Eloquent\Builderis passed. The Eloquent Builder don't have the$bindingsattribute so it'll fail.So my doubt is: this should be allowed? If yes, is very easy to fix it, just check if first param is a Eloquent Build and
getQuery()from it. Fixed. I guess that is valid this idea, but...Is possible to fix it basically by doing exactly what I said, directly on user code: