From 4c2447aeb5ad22a423ae61196c40415dd4b89c86 Mon Sep 17 00:00:00 2001 From: Zura Sekhniashvili Date: Fri, 8 Apr 2022 22:39:58 +0400 Subject: [PATCH] Change DbModel::primaryKey into static method --- Application.php | 3 ++- db/DbModel.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Application.php b/Application.php index 982cbfa..e7a61b3 100644 --- a/Application.php +++ b/Application.php @@ -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); diff --git a/db/DbModel.php b/db/DbModel.php index d65a42c..cca989b 100644 --- a/db/DbModel.php +++ b/db/DbModel.php @@ -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'; }