Closed TylerGauntlett closed 4 years ago
... 'connections' => [ 'sybase' => [ 'driver' => 'sqlsrv' ... ], ], ...
When using the lazy collection cursor() method with a model using a sqlsrv connection (sybase in my case), the each() iterator will exit after a model using the same connection is called. This does not happen with a mysql based driver.
cursor()
sqlsrv
each()
mysql
database.php
'connections' => [ 'sybase' => [ 'driver' => 'sqlsrv' ... ], 'mysql' => [ 'driver' => 'mysql' ... ], ],
MysqlUser.php
<?php namespace App\User; use Illuminate\Database\Eloquent\Model; class MysqlUser extends Model { protected $connection = 'mysql'; protected $table = 'users'; }
MysqlCar.php
<?php namespace App\Car; use Illuminate\Database\Eloquent\Model; class MysqlCar extends Model { protected $connection = 'mysql'; protected $table = 'cars'; }
Runtime
// Prints 0, 1, 2, 3, 4 MysqlUser::take(5)->cursor() ->each(function ($user, $key) { MysqlCar::first(); dump($key); });
SybaseUser.php
<?php namespace App\User; use Illuminate\Database\Eloquent\Model; class SybaseUser extends Model { protected $connection = 'sybase'; protected $table = 'users'; }
SybaseCar.php
<?php namespace App\Car; use Illuminate\Database\Eloquent\Model; class SybaseCar extends Model { protected $connection = 'sybase'; protected $table = 'cars'; }
// Only prints 0 SybaseUser::take(5)->cursor() ->each(function ($user, $key) { SybaseCar::first(); dump($key); });
Please fill out your DB driver and version.
I've just run into this exact issue today.
Description:
When using the lazy collection
cursor()
method with a model using asqlsrv
connection (sybase in my case), theeach()
iterator will exit after a model using the same connection is called. This does not happen with amysql
based driver.Steps To Reproduce:
Connection Setup
database.php
Working Example With
mysql
DriverMysqlUser.php
MysqlCar.php
Runtime
Failing Example With
sqlsrv
DriverSybaseUser.php
SybaseCar.php
Runtime