Create gridview joining one table with sum of columns from two other different tables

I have a table called store with fields: ID, id_master, regiao, user, atendedor, store_location. I want to display these columns and two other columns from separated tables. I want to display the sum of the columns based on the ID of the first table, meaning one table will relate to the first by ID (store.ID => ngin_agent_detail.CLIENT_ID) and the other table will relate to the first by user(store.user=>sap.created_by).

I have made these relations in first table model:

public function getNginAgentDetail()


    return $this->hasOne(NginAgentDetail::className(),['CLIENT_ID' => 'ID']);        


public function getSap()


    return $this->hasOne(Sap::className(),['Criado_por' => 'user']);        


How can i achieve this, joining three tables with sum of columns based on relations? I hope the question is clear enough or not i’ll post more details.

Could you give us the ER of the 3 tables?

I’m afraid you might have defined wrong relations among them.

Store N --- 1 NginAgentDetail

Store N --- 1 Sap

Your definitions say that Store has one NginAgentDetail and Store has one Sap. Is that correct?