From a29929846ff5901ffdd3f156dd6e733977183f75 Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Wed, 14 Sep 2016 14:31:15 -0400 Subject: [PATCH] Create hasPublicId property on models and use it to determine whether to set a public id --- app/Models/AccountGatewaySettings.php | 5 +++++ app/Models/EntityModel.php | 15 +++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/Models/AccountGatewaySettings.php b/app/Models/AccountGatewaySettings.php index 37f12e90c7..6b95c585c0 100644 --- a/app/Models/AccountGatewaySettings.php +++ b/app/Models/AccountGatewaySettings.php @@ -12,6 +12,11 @@ class AccountGatewaySettings extends EntityModel */ protected $dates = ['updated_at']; + /** + * @var bool + */ + protected static $hasPublicId = false; + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/EntityModel.php b/app/Models/EntityModel.php index b64f40ad54..c626f838f4 100644 --- a/app/Models/EntityModel.php +++ b/app/Models/EntityModel.php @@ -15,6 +15,12 @@ class EntityModel extends Eloquent * @var bool */ public $timestamps = true; + + /** + * @var bool + */ + protected static $hasPublicId = true; + /** * @var array */ @@ -58,7 +64,7 @@ class EntityModel extends Eloquent } - try { + if (static::$hasPublicId) { $lastEntity = $lastEntity->orderBy('public_id', 'DESC') ->first(); @@ -67,13 +73,6 @@ class EntityModel extends Eloquent } else { $entity->public_id = 1; } - } catch - (QueryException $ex) { - // Code 42S22 is for an unknown column. - // If we get that code, we'll just swallow the error, since apparently this entity doesn't support public_ids. - if ($ex->getCode() !== '42S22') { - throw $ex; - } } return $entity;