robsonvn / laravel-couchdb

A CouchDB based Eloquent model and Query builder for Laravel
56 stars 28 forks source link

Failure on selecting field in a belongsToMany relationship #20

Open robsonvn opened 6 years ago

robsonvn commented 6 years ago

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.