laravel-query-detector icon indicating copy to clipboard operation
laravel-query-detector copied to clipboard

Eager loaded pivot relationships still show alert?

Open godbout opened this issue 7 years ago • 6 comments

Maybe I'm doing something wrong, not sure, but I don't think I've got a N+1 query issue in my case. I still have the alert though.

I have a Section class. We can get the students and/or teachers of a section through properties. Those properties are eager loaded through the $with public variable. Still, the alert shows up.

public function students()
    {
        return $this->belongsToMany(User::class)->wherePivot('type', 'STUDENT');
    }

    public function teachers()
    {
        return $this->belongsToMany(User::class)->wherePivot('type', 'TEACHER');
    }

It happens when I show a section. I get the Section object through the controller method, and just send it back to the view with all eager loaded.

Any idea?

godbout avatar Jul 30 '18 05:07 godbout

Hi. Did you find any solution? I'm facing the same issue. I have eager loaded relations on the $with property.. but the alert still shows.

@mpociot Is there a way for not triggering the alert when using $with?

jtrod avatar Mar 23 '20 10:03 jtrod

can't remember. probably gave up.

godbout avatar Mar 23 '20 12:03 godbout

similar problems. can it be used for multy relation? like users has relation to roles and anyrelation. in my controllers :

$usersBinding = User::with(['roles', 'anyrelation' => function($teacher){
            $teacher->with(['classAcceses' => function($classAccess){
                $classAccess->with('class')->get();
            }])->get();
        }])->whereIn('id',$roleIds);

still geting alert in the browser. Any Solutions?

rhamadsani avatar May 21 '21 02:05 rhamadsani

Anyway... https://twitter.com/taylorotwell/status/1395087054254526474?s=20

jtrod avatar May 21 '21 12:05 jtrod

Anyway... https://twitter.com/taylorotwell/status/1395087054254526474?s=20

where should i place that code?

perffy avatar Jun 23 '21 17:06 perffy

Anyway... https://twitter.com/taylorotwell/status/1395087054254526474?s=20

where should i place that code?

Hej @perffy, this is documented.

dsturm avatar Jul 09 '21 12:07 dsturm