laravel-couchdb icon indicating copy to clipboard operation
laravel-couchdb copied to clipboard

Failure on selecting field in a belongsToMany relationship

Open robsonvn opened this issue 6 years ago • 0 comments

Code example:

  public function users(){
    return $this->belongsToMany('App\User')->select(['first_name']);
  }

Error message:

`` (1/1) ErrorExceptionInvalid argument supplied for foreach()

in BelongsToMany.php line 264 ``

Probable cause:

When the user specifies the columns it's ignoring the foreign key column "company_ids" which impacts the crossmatch between users and companies.

Suggest solution

Force foreign key to be selected as _id and _rev.

robsonvn avatar May 25 '18 03:05 robsonvn