从其他三个表yii2将数据插入表

时间:2019-06-22 08:50:25

标签: php mysql sql yii2

有4个表-用户,假期,单事件,notifications_events。我需要将数据从其他3个表插入notifications_events。表格:

users:
id
username
password_hash
birthday
status


holidays:
id
month
day
name
description


single-events:
id
date_at
name
description


notifications_events:
id
date_at
type
event_id
message

我正在尝试此代码,但无法正常工作:

public function actionInsert()
{
    $model = new NotificationsEvents();
    $model->date_at = (new Query())
        ->select(['single-events.date_at'])
        ->from('single-events')
        ->join('LEFT JOIN', 'user', 'user.birthday');

    $model->event_id = (new Query())
        ->select(['single-events.id'])
        ->from('single-events')
        ->join('LEFT JOIN', 'user', 'user.id');

    $model->save();
}

因此,我需要将其他3个表中的数据放入notifications_events中。例如,event_id字段必须等于holiday.id或user.id,date_at必须等于user.birthday,以及其他日期。在类型中,您需要输入事件的类型,可以使用数字,仍然可以对消息进行评分。帮助提出要求。 在php yii2框架上是理想的。尽管我会是相当普通的sql。

0 个答案:

没有答案