Laravel의 Eloquent ORM에서 작동하지 않는 getPaginationCount () 함수

콜린 M

별도로 사용하기 위해 Eloquent 모듈을 꺼내고 있지만 QueryBuilder 함수에 액세스 할 수 있습니다. 그것들을 제외하고는 모두 작동합니다.

count () 및 getPaginationCount ()를 실행하면 count ()는 올바른 값을 반환하지만 getPaginationCount ()는 쿼리를 실행하도록 명령하지 않은 것처럼 Illuminate \ Database \ Eloquent \ Builder 객체 만 반환합니다. 그러나 쿼리 로그에서 두 개의 쿼리를 볼 수 있으며 이상하게도 둘 다 동일한 쿼리를 실행합니다.

require 'vendor/autoload.php';  

use Illuminate\Database\Capsule\Manager as Capsule;  

$capsule = new Capsule;

$capsule->addConnection(array(
    'driver'    => 'mysql',
    'host'      => TECHDB_HOST,
    'database'  => TECHDB_DBNAME,
    'username'  => TECHDB_USER,
    'password'  => TECHDB_PASS,
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => ''
));

$capsule->bootEloquent();


class Indicator extends Illuminate\Database\Eloquent\Model {
    public $timestamps = false;
    public $table = "indicator_performance";
}

$query = Indicator::where('symbol', '=', 'IBM')->forPage(1,2);

var_dump($query->count()); //Correctly prints '13'

var_dump($query->getPaginationCount()); //dumps the 'Illuminate\Database\Eloquent\Builder' object

다음은 쿼리 로그입니다.

array (size=2)
  0 => 
    array (size=3)
      'query' => string 'select count(*) as aggregate from `indicator_performance` where `symbol` = ? limit 2 offset 0' (length=93)
      'bindings' => 
        array (size=1)
          0 => string 'IBM' (length=3)
      'time' => float 4.85
  1 => 
    array (size=3)
      'query' => string 'select count(*) as aggregate from `indicator_performance` where `symbol` = ? limit 2 offset 0' (length=93)
      'bindings' => 
        array (size=1)
          0 => string 'IBM' (length=3)
      'time' => float 4.24

편집하다:

호출 count()후 사용할 때 함수에 더 일반적인 버그가 노출 된 것 같습니다 forPage(). 다음 결과를 살펴보십시오.

$query = Indicator::where('symbol', '=', 'IBM');

var_dump($query->count()); //Correctly returns '13'
var_dump($query->forPage(0, 5)->count()); //Correctly returns '13'
var_dump($query->forPage(1, 5)->count()); //Correctly returns '13'
var_dump($query->forPage(2, 5)->count()); //Returns null. Should return '13' or '3', depending on implementation.
자렉 차 치크

코드 (및 Laravel)에는 두 가지 문제가 있습니다.

  1. getPaginationCount()Eloquent Builder에서 호출 된 메서드는 Query Builder 클래스에서 메서드를 실행하지만 결과를 반환하지 않습니다. 대신 $this.

  2. getPaginationCount()재설정하지 않습니다 limitoffset쿼리에 나는 버그가 가정 수를 얻을 수 있습니다. 결과적으로 null오프셋이 1보다 높은 값으로 설정 될 때마다 반환 forPage($page)됩니다 $page > 1.

즉, 또는 count()대신 사용 하는 것이 좋습니다 getPaginationCount().

// first get the count
$count = $query->getQuery()  // get the base Query Builder directly
    ->getPaginationCount();  // in order to return the count

// then use forPage
$query->forPage(1,5);

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Eloquent Javascript에서 파이 계수 함수가 어떻게 작동하는지 설명 하시겠습니까?

Eloquent ORM laravel에서 마지막 삽입 ID를 얻는 방법

2099 년이 Laravel에서 작동하지 않는 strtotime 함수를 사용할 때

Laravel Orderby가 Eloquent에서 작동하지 않습니다.

커서가 작동하지 않는 SQL Server 함수의 재귀

laravel : Eloquent Query에서 LOWERCASE 함수를 사용하는 방법?

Laravel Eloquent with () 메서드는 'where'에서는 작동하지만 'Model :: find ()'에서는 작동하지 않습니다.

Laravel Eloquent는 의도 한대로 작동하지 않습니다.

로드하기 위해 작동하지 않는 함수에는 많은 관계 데이터가 있습니다 laravel Model Eloquent

React의 componentDidMount에서 작동하지 않는 비동기 / 대기 함수 호출

Eloquent 쿼리는 별도로 작동하지만 하위 쿼리에서 함께 작동하지 않습니다.

Pandas에서 작동하지 않는 사용자 정의 함수

`this` 함수는 nodejs의 모듈에서 작동하지 않습니다.

whereHas 및 whereDoesntHave는 laravel eloquent에서 예상대로 작동하지 않습니다.

laravel eloquent의 다 대다 relationschop은 pluck ()에서 작동하지 않습니다.

laravel에서 작동하지 않는 Eloquent create

Laravel에서 작동하지 않는 Eloquent 쿼리

.click () jQuery 함수는 하나의 ID에 대해 작동하지만 변수는 작동하지 않습니다.

IBAction에서는 작동하지만 Swift의 viewDidLoad에서는 작동하지 않는 함수

Laravel 5에서 동적 수의 Eloquent 쿼리를 작성하는 방법은 무엇입니까?

슬라이더에서 의도한 대로 작동하지 않는 hasClass() 함수

Laravel isNotEmpty()가 Eloquent 모델에서 작동하지 않습니다

Eloquent JavaScript 3판의 5장 고차 함수의 예제에서 작동하지 않는 한 어떻게 작동합니까?

Laravel5.8에서 작동하지 않는 hasFile 함수

Laravel 5.8 Eloquent는 원시 덤프 쿼리가 작동함에도 불구하고 의도한 대로 작동하지 않습니다.

Laravel Eloquent ORM 쿼리가 작동하지 않음 Laravel v6.9

모듈의 콜백에서 작동하지 않는 비동기 함수

비동기 함수 내에서 작동하지 않는 NodeJ의 배열 푸시

Laravel eloquent에서 조건이 작동하지 않는 배수