Skip to content

Commit

Permalink
Change DbModel::primaryKey into static method
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodeholic committed Apr 8, 2022
1 parent 4b106fd commit 4c2447a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static function isGuest()
public function login(UserModel $user)
{
$this->user = $user;
$primaryKey = $user->primaryKey();
$className = get_class($user);
$primaryKey = $className::primaryKey();
$value = $user->{$primaryKey};
Application::$app->session->set('user', $value);

Expand Down
2 changes: 1 addition & 1 deletion db/DbModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class DbModel extends Model
{
abstract public static function tableName(): string;

public function primaryKey(): string
public static function primaryKey(): string
{
return 'id';
}
Expand Down

0 comments on commit 4c2447a

Please sign in to comment.