staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

"This query requires an additional trait." exception #137

Closed staudenmeir closed 3 years ago

staudenmeir commented 3 years ago

This query requires an additional trait. Please add the Staudenmeir\EloquentHasManyDeep\HasTableAlias trait to App\Models\YourModel.

Queries with has()/whereHas()/withCount()/loadCount() require a temporary table alias to work when the parent table also appears as an intermediate table. The package can set this alias, but it requires an additional trait in the affected model.

Please add the HasTableAlias trait to the parent model that is shown in the exception message:

class YourModel extends Model
{
    use \Staudenmeir\EloquentHasManyDeep\HasTableAlias;
}

Then run the query again.