mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
关联字段默认转换为小写
This commit is contained in:
@@ -439,12 +439,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
public function isUpdate($data = [])
|
public function isUpdate($data = [])
|
||||||
{
|
{
|
||||||
$data = $data ?: $this->data;
|
$data = $data ?: $this->data;
|
||||||
$pk = $this->pk;
|
// 判断主键
|
||||||
// 如果存在主键数据 则自动作为更新条件
|
$pk = $this->pk;
|
||||||
if (is_string($pk) && isset($data[$pk])) {
|
if (is_string($pk) && isset($data[$pk])) {
|
||||||
return true;
|
return true;
|
||||||
} elseif (is_array($pk)) {
|
} elseif (is_array($pk)) {
|
||||||
// 增加复合主键支持
|
|
||||||
foreach ($pk as $field) {
|
foreach ($pk as $field) {
|
||||||
if (isset($data[$field])) {
|
if (isset($data[$field])) {
|
||||||
return true;
|
return true;
|
||||||
@@ -577,7 +576,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
{
|
{
|
||||||
$model = $this->parseModel($model);
|
$model = $this->parseModel($model);
|
||||||
$localKey = $localKey ?: $this->pk;
|
$localKey = $localKey ?: $this->pk;
|
||||||
$foreignKey = $foreignKey ?: $this->name . '_id';
|
$foreignKey = $foreignKey ?: strtolower($this->name) . '_id';
|
||||||
$this->relation = self::HAS_ONE;
|
$this->relation = self::HAS_ONE;
|
||||||
return $model::where($foreignKey, $this->data[$localKey]);
|
return $model::where($foreignKey, $this->data[$localKey]);
|
||||||
}
|
}
|
||||||
@@ -587,7 +586,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
{
|
{
|
||||||
$model = $this->parseModel($model);
|
$model = $this->parseModel($model);
|
||||||
$foreignKey = $foreignKey ?: $this->pk;
|
$foreignKey = $foreignKey ?: $this->pk;
|
||||||
$localKey = $localKey ?: basename(str_replace('\\', '/', $model)) . '_id';
|
$localKey = $localKey ?: strtolower(basename(str_replace('\\', '/', $model))) . '_id';
|
||||||
$this->relation = self::BELONGS_TO;
|
$this->relation = self::BELONGS_TO;
|
||||||
return $model::where($foreignKey, $this->data[$localKey]);
|
return $model::where($foreignKey, $this->data[$localKey]);
|
||||||
}
|
}
|
||||||
@@ -597,7 +596,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
{
|
{
|
||||||
$model = $this->parseModel($model);
|
$model = $this->parseModel($model);
|
||||||
$localKey = $localKey ?: $this->pk;
|
$localKey = $localKey ?: $this->pk;
|
||||||
$foreignKey = $foreignKey ?: $this->name . '_id';
|
$foreignKey = $foreignKey ?: strtolower($this->name) . '_id';
|
||||||
$this->relation = self::HAS_MANY;
|
$this->relation = self::HAS_MANY;
|
||||||
return $model::where($foreignKey, $this->data[$localKey]);
|
return $model::where($foreignKey, $this->data[$localKey]);
|
||||||
}
|
}
|
||||||
@@ -607,7 +606,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
{
|
{
|
||||||
$model = $this->parseModel($model);
|
$model = $this->parseModel($model);
|
||||||
$foreignKey = $foreignKey ?: $this->pk;
|
$foreignKey = $foreignKey ?: $this->pk;
|
||||||
$localKey = $localKey ?: basename(str_replace('\\', '/', $model)) . '_id';
|
$localKey = $localKey ?: strtolower(basename(str_replace('\\', '/', $model))) . '_id';
|
||||||
$this->relation = self::BELONGS_TO_MANY;
|
$this->relation = self::BELONGS_TO_MANY;
|
||||||
return $model::where($foreignKey, $this->data[$localKey]);
|
return $model::where($foreignKey, $this->data[$localKey]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user