From f96cd44c3ba6523ac8af2edcd610348cb99a2edf Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 8 Jul 2019 18:16:56 +0500 Subject: [PATCH] Create account roles with lock to avoid duplicates --- app/models/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/account.rb b/app/models/account.rb index 5c78264..74b8247 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -101,7 +101,7 @@ class Account < ApplicationRecord self.class.define_dynamic_method role.name, resource end - roles << role + account_roles.where(role: role).first_or_create! role end