Models and relations

Hello y have the next:

Custumer model:

customer_id

custumer_name

Contact model

Has many relation with custumer model

contact_id

contact_name

contact_custumer_id

Phones models

Has many reltaion with contact model

phone_id

phone_numbre

phone_contact_id

I need the next:

  1. All phones of all contacts for a cutomer by ID

can you help me please?

ok here this might help you get some idea


<?php


namespace app\models;


class Customer extends \yii\db\ActiveRecord

{

    // ...

    public function getContacts()

    {

        return $this->hasMany(Contact::className(), ['contact_customer_id' => 'id']);

    }

    // ...

}


class Contact extends \yii\db\ActiveRecord

{

    // ...

    public function getPhone()

    {

        return $this->hasMany(Phone::className(), ['phone_contact_id' => 'id']);

    }

    // ...

}


class Phone extends \yii\db\ActiveRecord

{

}




$phones = Customer::find($id)->getContacts()->getPhones();