Scalr\Model\Entity\Farm::saveTeams PHP Method

saveTeams() public method

This method should only be called within a transaction.
public saveTeams ( EntityIterator | Team[] $teams )
$teams Scalr\Model\Collections\EntityIterator | Scalr\Model\Entity\Account\Team[] Collection of the Teams
    public function saveTeams($teams)
    {
        if (!$this->db()->transCnt) {
            throw new LogicException("This method should only be called within a transaction!");
        }
        $farmTeam = new FarmTeam();
        if (!empty($teams)) {
            $values = [];
            $args = [];
            $farmIdType = $farmTeam->getIterator()->getField('farmId')->type;
            $farmIdWh = $farmIdType->wh();
            $teamIdType = $farmTeam->getIterator()->getField('teamId')->type;
            $teamIdWh = $teamIdType->wh();
            foreach ($teams as $team) {
                $values[] = "({$farmIdWh}, {$teamIdWh})";
                $args[] = $farmIdType->toDb($this->id);
                $args[] = $teamIdType->toDb($team->id);
            }
        }
        FarmTeam::deleteByFarmId($this->id);
        if (!empty($values)) {
            $this->db()->Execute("INSERT IGNORE INTO {$farmTeam->table()} (`farm_id`, `team_id`) VALUES " . implode(', ', $values), $args);
        }
    }