LazyRecord\BaseModel::loadOrCreate PHP Method

loadOrCreate() public method

Create a record if the record does not exists Otherwise the record should be updated with the arguments.
public loadOrCreate ( array $args, array $byKeys = null )
$args array
$byKeys array it's optional if you defined primary key
    public function loadOrCreate(array $args, $byKeys = null)
    {
        $ret = null;
        $pk = static::PRIMARY_KEY;
        if ($byKeys) {
            $ret = $this->load(array_intersect_key($args, array_fill_keys((array) $byKeys, 1)));
        } elseif ($pk && isset($args[$pk])) {
            $val = $args[$pk];
            $ret = $this->load(array($pk => $val));
        } else {
            throw new PrimaryKeyNotFoundException('primary key is not defined.');
        }
        if ($ret && $ret->success || $pk && isset($this->_data[$pk]) && $this->_data[$pk]) {
            // is loaded
            return $ret;
        } else {
            // record not found, create
            return $this->create($args);
        }
    }