E
E
EvgMul2018-09-28 21:09:01
Yii
EvgMul, 2018-09-28 21:09:01

How to send a request to get rows from 3 tables at once to dataProvider?

First of all, I'm wondering if this is even possible.
The point is this. I have 3 tables somewhat different in their structure, but their essence is the same.
Right now I'm looking for records like this:

public function search($params)
    {
        $this->load($params);

        if ($this->article_type == 2) {
            $query = Journals::find()
                ->where(['journals.active' => self::ACTIVE])
                ->groupBy('journals.id');
        } elseif ($this->article_type == 3) {
            $query = Parks::find()
                ->joinWith('regionsParkRelation as rpr')
                ->groupBy('parks.id');
        } else {
            $query = Articles::findAll()
                ->joinWith('district')
                ->where(['active' => self::ACTIVE])
        }

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
//.............

Ie I look in the request if the user has specified a filter by the category of articles, then I give him the appropriate ones. And if the filter is not specified, then I simply show it only one category from one table.
Actually the question is, can I send a query to the ActiveDataProvider that takes data from all 3 tables if the filter is not specified?
And if there is such a possibility, tell me, please, how to implement it?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-09-28
@webinar

No, this will not work without adhesive tape and an ax, at best, you need to make a union and combine the request. But your data is completely different. In excel, you cannot even manually merge tables with different columns, and even their number.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question