dimanche 31 janvier 2016

Laravel many to many relationship returning unexpected result

I have problems with my many to many relationship returned data. I have 3 tables to define this relationship users, institutes and the pivot table users_institutes. The data in my users_institutes is in the image.

enter image description here

My relationship is defined by the following code.

public function super_user_institutes()
{
    return $this->belongsToMany('App\Institute', 'users_institutes')
        ->wherePivot('role', 'inst_superuser')
        ->orWherePivot('role', 'inst_admin')
        ->orWherePivot('role', 'inst_staff')
        ->withPivot('role');
}

Now, for the user I'm trying to get the relations for has the id 2. So, now if I use

$user->super_user_institutes;

I get the following rows in response: 1, 2, 3, 9, 10, 11, 12 (7 rows).

Where I expect the following rows: 1, 2, 3.

Am I expecting a wrong result? or my relationship definition is wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire