LazyRecord\BaseModel::createOrUpdate PHP Method

createOrUpdate() public method

If the record exists, then the record should be updated. If the record does not exist, then the record should be created.
public createOrUpdate ( array $args, array $byKeys = null )
$args array
$byKeys array
    public function createOrUpdate(array $args, $byKeys = null)
    {
        $pk = static::PRIMARY_KEY;
        $ret = null;
        if ($pk && isset($args[$pk])) {
            $val = $args[$pk];
            $ret = $this->load(array($pk => $val));
        } elseif ($byKeys) {
            $conds = array();
            foreach ((array) $byKeys as $k) {
                if (array_key_exists($k, $args)) {
                    $conds[$k] = $args[$k];
                }
            }
            $ret = $this->load($conds);
        }
        if ($ret && $ret->success || $pk && isset($this->_data[$pk])) {
            return $this->update($args);
        } else {
            return $this->create($args);
        }
    }