1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Create hasPublicId property on models and use it to determine whether to set a public id

This commit is contained in:
Joshua Dwire 2016-09-14 14:31:15 -04:00
parent 76af2f3e13
commit a29929846f
2 changed files with 12 additions and 8 deletions

View File

@ -12,6 +12,11 @@ class AccountGatewaySettings extends EntityModel
*/
protected $dates = ['updated_at'];
/**
* @var bool
*/
protected static $hasPublicId = false;
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/

View File

@ -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;