M
M
Michael2018-12-27 09:51:47
Yii
Michael, 2018-12-27 09:51:47

How to pass the parent id of the added object (child element) to the session?

Hello everybody! There is a function to add an object to the session, the code is given below, the code is working. Please tell me the following, how to do that if I add an object of the "Monitor" type to the session, then in the session 'contract_id' receives a parameter from the parent element (User's Workplace), in this case the number 6? Adding 'contract_id' to the session comes from the associated table.
5c24741ee9449411341272.png

public function addToDoc($accept){
    $_SESSION['form'][$accept->id] = [
        'equipment' => $accept->equipment,
        'type_id' => $accept->type_id,
        'contract_id' => $accept->type->contract_id,
        'shk_osk' => $accept->shk_osk,
        'serial_number' => $accept->serial_number,
    ];
}

Table relationships
Таблица accept
public function getType(){
    return $this->hasOne(Type::className(), ['id' => 'type_id']);
}

Таблица type
public function getAccepts(){
    return $this->hasMany(Accept::className(), ['type_id' => 'id']);
}

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