There is such a request:

SELECT id, name_film, created_at FROM `fl_films` UNION SELECT id, name_serial, created_at FROM `fl_serial` ORDER BY created_at DESC LIMIT 0 , 20 

How can I arrange it in ActiveRecord , so that later I can use the connections of the models of these tables.

    2 answers 2

    In this task, https://github.com/yiisoft/yii2/issues/7992, the use of UNION when composing a query to the database is discussed.

    Here is also discussed UNION in Yii2

      The issue is solved hard but the model is solved so

       <?php namespace common\models; use Yii; /** * This is the model class for table "fl_actours". * * @property integer $id * @property string $name * @property string $biography */ class FilmsFordate extends \yii\db\ActiveRecord { public static function tableName() { return 'fl_filmsFordate'; } }?> 

      Controller

        Yii::$app->db->createCommand(" CREATE OR REPLACE VIEW fl_filmsFordate(id,name,created_at) AS SELECT id, name_film, created_at FROM `fl_films` UNION SELECT id, name_serial, created_at FROM `fl_serial` ORDER BY created_at DESC LIMIT 0 , 20"); $last= FilmsFordate::find()->all(); 

      the truth with the tie must be updated, and everything works. This article helped a lot. Thanks to all.