A
A
asferot2019-02-06 11:02:08
Yii
asferot, 2019-02-06 11:02:08

How to make join yii2?

There are 2 related tables. In one, which is called - Applications - there is a field f1740 - it shows the manager's id and refers to another table - Users, where in the field f483 - the manager's name.
Here is a table call with managers:

public function actionManagersSelect()
    {
        $request = Yii::$app->request;
        if ($request->isPost) {
            $data = Managers::find()->select(['f483', 'f5021'])->where(['id' => [5, 7, 9, 33, 10, 30, 35, 16]])/*->indexBy('f483')*/->all();
            Yii::$app->response->format = Response::FORMAT_JSON;
            return $data;
        }else throw new \yii\web\BadRequestHttpException;
    }

Here is a call to the table with claims:
public function actionZayavka()
    {
        $request = Yii::$app->request;
        if ($request->isPost) {
            $data = Zayavka::find()->select(['f1740', ])->orderBy('id desc')->limit(5)->all();
            Yii::$app->response->format = Response::FORMAT_JSON;
            return $data;
        }else throw new \yii\web\BadRequestHttpException;
    }

The question is how to assign the value f483 to the f1740 field so that instead of id the manager's name is displayed, which is stored in the f483 field?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-02-06
@webinar

how to assign the value f483 to the f1740 field so that the name of the manager is displayed instead of id,

I don't think join should be used for this. And in general, a replacement of this kind is a bad idea, it is better to make a separate getter, but in general it is possible through afterFind.
And can I have a photo of a person who calls attributes that way?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question