mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
改进Validate类的uniuqe验证规则 第一个参数传入不带数据表前缀的表名 并且支持主键自动获取
This commit is contained in:
@@ -602,7 +602,7 @@ class Validate
|
||||
if (is_string($rule)) {
|
||||
$rule = explode(',', $rule);
|
||||
}
|
||||
$db = Db::table($rule[0]);
|
||||
$db = Db::name($rule[0]);
|
||||
$field = isset($rule[1]) ? $rule[1] : $field;
|
||||
|
||||
if (strpos($field, '^')) {
|
||||
@@ -617,7 +617,7 @@ class Validate
|
||||
$map[$field] = $data[$field];
|
||||
}
|
||||
|
||||
$key = strval(isset($rule[3]) ? $rule[3] : 'id');
|
||||
$key = strval(isset($rule[3]) ? $rule[3] : $db->getPk());
|
||||
if (isset($rule[2])) {
|
||||
$map[$key] = ['neq', $rule[2]];
|
||||
} elseif (isset($data[$key])) {
|
||||
|
||||
@@ -911,6 +911,17 @@ class Query
|
||||
return $fetch ? $_info[$guid][$fetch] : $_info[$guid];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前模型对象的主键
|
||||
* @access public
|
||||
* @param string $table 数据表名
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPk($table = '')
|
||||
{
|
||||
return $this->getTableInfo($table, 'pk');
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数绑定
|
||||
* @access public
|
||||
@@ -1044,7 +1055,7 @@ class Query
|
||||
*/
|
||||
protected function parsePkWhere($data, &$options)
|
||||
{
|
||||
$pk = $this->getTableInfo($options['table'], 'pk');
|
||||
$pk = $this->getPk($options['table']);
|
||||
// 获取当前数据表
|
||||
if (!empty($options['alias'])) {
|
||||
$alias = $options['alias'];
|
||||
@@ -1137,7 +1148,7 @@ class Query
|
||||
{
|
||||
$options = $this->parseExpress();
|
||||
if (empty($options['where'])) {
|
||||
$pk = $this->getTableInfo($options['table'], 'pk');
|
||||
$pk = $this->getPk($options['table']);
|
||||
// 如果存在主键数据 则自动作为更新条件
|
||||
if (is_string($pk) && isset($data[$pk])) {
|
||||
$where[$pk] = $data[$pk];
|
||||
@@ -1333,7 +1344,7 @@ class Query
|
||||
*/
|
||||
public function chunk($count, $callback, $column = null)
|
||||
{
|
||||
$column = $column ?: $this->getTableInfo('', 'pk');
|
||||
$column = $column ?: $this->getPk();
|
||||
$options = $this->getOptions();
|
||||
$resultSet = $this->limit($count)->order($column, 'asc')->select();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user