B
B
balex7772019-09-13 07:48:23
Yii
balex777, 2019-09-13 07:48:23

How to select data from several linked tables in YII1 with one query through links?

Hello, I have 7 tables, here is the 5d7b1fe9c45d7509903551.png
screen
I made such connections
Contacts

public function relations()
    {
        return array(
            'company' => array(self::BELONGS_TO, 'Company', 'company_id'),
        );
    }

company
public function relations()
    {
        return array(
            'category' => array(self::BELONGS_TO, 'BusinessCategory', 'category_id'),
            'contacts' => array(self::HAS_MANY, 'Contacts', 'company_id'),
            'staffCompanies' => array(self::HAS_MANY, 'StaffCompany', 'company_id'),
        );
    }

business category
public function relations()
    {
        return array(
            'companies' => array(self::HAS_MANY, 'Company', 'category_id'),
        );
    }

StaffCompany
public function relations()
    {
        return array(
            'emailStaffCompanies' => array(self::HAS_MANY, 'EmailStaffCompany', 'staff_company_id'),
            'networkStaffCompanies' => array(self::HAS_MANY, 'NetworkStaffCompany', 'staff_company_id'),
            'phoneStaffCompanies' => array(self::HAS_MANY, 'PhoneStaffCompany', 'staff_company_id'),
            'company' => array(self::BELONGS_TO, 'Company', 'company_id'),
        );
    }

PhoneStaffCompany, NetworkStaffCompany, EmailStaffCompany
public function relations()
    {
        return array(
            'staffCompany' => array(self::BELONGS_TO, 'StaffCompany', 'staff_company_id'),
        );
    }

I tried to make such a request to Contacts
Contacts::model()->with('company')->findAll(array("condition"=>"user_id = $user_id"));

but it gives out only Contact and Company
A, its Staff (their phones are soap) and the category
How is it better to make a request so that I contact the contact once, and he collects all the information in other tables by connections?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question