How to select fields from two tables in one Model PHP file which generated by gii

Hello guys:

I have two table:

user: id,name,unit_id;

unit: id,unitname

I want to view user’s index like below:


|id | name | unit_id |unitname|


It’s show fields from two tables,so I want to know how to select fields from two tables in one Model php file which generated by Gii, such like excutes “select a.id as id,a.name as name, a.unit_id as unit_id,b.unitname as unitname from user a inner join unit b on a.unit_id=b.id”.

thanks

You should read up on ActiveRecord, particularly Working with Relational Data: http://www.yiiframework.com/doc-2.0/guide-db-active-record.html