Skip to content

Commit

Permalink
Check driver before exists query
Browse files Browse the repository at this point in the history
  • Loading branch information
rawilk committed Aug 1, 2022
1 parent a859c52 commit 0fc62ca
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Concerns/MustBeApproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ protected static function insertApprovalRequest($model)
*/
protected static function approvalModelExists($model): bool
{
$driver = Approval::make()->getConnection()->getConfig()['driver'] ?? 'sqlite';

if ($driver === 'sqlite') {
return Approval::where([
['state', '=', ApprovalStatus::Pending],
['new_data', '=', json_encode($model->getDirty())],
['original_data', '=', json_encode($model->getOriginalMatchingChanges())],
])->exists();
}

return Approval::where('state', ApprovalStatus::Pending)
->whereJsonContains('new_data', $model->getDirty())
->whereJsonContains('original_data', $model->getOriginalMatchingChanges())
Expand Down

0 comments on commit 0fc62ca

Please sign in to comment.