public function add() { $person = new Person(); $person->first_name = $this->firstName; $person->last_name = $this->lastName; $person->second_name = $this->secondName; $person->save(); $position = new Position(); $position->name = $this->positionName; $position->save(); $employee = new Employee(); $employee->person_id = $person->id; $employee->salary = $this->salary; $employee->save(); }
public function add() { $person = new Person(); $person->first_name = $this->firstName; $person->last_name = $this->lastName; $person->second_name = $this->secondName; $person->save(); $employee = new Employee(); $employee->person_id = $person->id; $employee->salary = $this->salary; $employee->save(); foreach ($this->positions as $posName) { $position = Position::find()->where(['name' => $posName])->one(); if ($position == NULL) { $position = new Position(); $position->name = $posName; $position->save(); } $employeePositions = new EmployeePositions(); $employeePositions->employee_id = $employee->id; $employeePositions->position_id = $position->id; $employeePositions->save(); } }