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);
}
}