How to refer ambiguous columns in joins

I have the following code:


  $categories = QuizCategory::find()

       ->select('{{%quiz_category}}.id,{{%quiz_category}}.name, count(*) as questionCount')

       ->innerJoinWith('questions')          

       ->groupBy('{{%quiz_category}}.id') 

       ->orderBy('{{%quiz_category}}.id ASC')

       ->all();

In this code I use {{%quiz_category}}.id. It works perfectly, but I’d like to ask if there is another way to refer ambiguous columns.

tbl_quiz_category is the name of the table, and I’d like not having to write the table name. (I already have defined the table name in the model).

You can reuse that definition:


  

$categories = QuizCategory::find()

  ->select('t.id, t.name, count(*) as questionCount')

  ->from(['t' => QuizCategory::tableName()])

  ->innerJoinWith('questions')      	

  ->groupBy('t.id') 

  ->orderBy('t.id ASC')

  ->all();



Great! It works perfectly!