Skip to content

Commit

Permalink
Merge pull request #43 from yurenzhen/feature/string-primary-key-support
Browse files Browse the repository at this point in the history
修复当user_id类型为string时的user_id大小计算错误问题:
  • Loading branch information
libern authored May 17, 2019
2 parents 38a820b + b5ea49e commit d8747e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 0 additions & 16 deletions src/Someline/Base/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,6 @@ protected function updateIps()
}
}

/**
* check the $user_id is valid.
*
* @param int|string $user_id
* @return bool
*/
protected function validUserId($user_id): bool
{
if ('int' === $this->keyType)
return $user_id > 0;

if ('string' === $this->keyType)
return strlen($user_id) > 0;
}

/**
* Update the creation and update by users.
*
Expand Down Expand Up @@ -313,5 +298,4 @@ public function getUpdatedAt()
return $this->updated_at;
}


}
18 changes: 17 additions & 1 deletion src/Someline/Model/Traits/BaseModelEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function onCreating()
// auto set user id
if ($this->autoUserId && empty($this->user_id)) {
$user_id = $this->getAuthUserId();
if ($user_id > 0) {
if ($this->validUserId($user_id)) {
$this->user_id = $user_id;
}
}
Expand Down Expand Up @@ -94,4 +94,20 @@ public function onRestoring()
public function onRestored()
{
}

/**
* check the $user_id is valid.
*
* @param int|string $user_id
* @return bool
*/
protected function validUserId($user_id): bool
{
if ('int' === $this->keyType)
return $user_id > 0;

if ('string' === $this->keyType)
return strlen($user_id) > 0;
}

}

0 comments on commit d8747e6

Please sign in to comment.