Column 'is_published' in where clause is ambiguous

Basically, I have 2 models with the same is_published boolean.
first model belongs to Many 2nd model and both has a scope isPublished.

now, the relationships between them is like this:

public $hasManyThrough = [
        'lessons_published' => [
            'through' => Module::class,
            'scope' => 'published'

when I try to access the relation lessons_published from an instance of the 1st model Course, I have this sql error

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'is_published' in where clause is ambiguous (SQL: 

anyone encoutnered this before?

Hi @chris,

I know it’s possible to specify the table in your scope, like this:

public function scopePublished($query, $filter) {
   $query->whereIn('your_table.is_published', $filter);

Would this work for you ?


ah super! it works great in the scope indeed.

also works fine here

                 ->withCount(['lessons' => function ($query) {
                     $query->where('table_lessons.is_published', true);

thanks a lot