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