Open
Description
Description
The issue occurs with the following query, when you join the two relational database models and attempt to use the whereHas into the third relation which is a MongoDB Model.
Example
class Tree extends Illuminate\Database\Eloquent\Model
{
use HybridRelations;
public function apples(): HasMany
{
return $this->hasMany(Apple::class, 'tree_id');
}
public function seeds(): HasMany
{
return $this->hasMany(Seed::class, 'tree_id');
}
}
class Apple extends Illuminate\Database\Eloquent\Model
{
use HybridRelations;
public function tree(): BelongsTo
{
return $this->belongsTo(Tree::class, 'tree_id');
}
public function seeds(): HasMany
{
return $this->hasMany(Seed::class, 'apple_id');
}
}
class Seed extends Jenssegers\Mongodb\Eloquent\Model
{
public function tree(): BelongsTo
{
return $this->belongsTo(Tree::class, 'tree_id');
}
public function apple(): BelongsTo
{
return $this->belongsTo(Apple::class, 'apple_id');
}
}
Tree::query()->first()->apples()->whereHas('seeds',
function ($query)
{
$query->whereIn('type', ['grannysmith']);
}
);
Exception
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous...