Commit 9f1a5f41 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Key uniq method refactored

parent 2d162ff9
...@@ -24,7 +24,7 @@ class Key < ActiveRecord::Base ...@@ -24,7 +24,7 @@ class Key < ActiveRecord::Base
end end
def unique_key def unique_key
query = Key.where('`key` = ?', key) query = Key.where(:key => key)
query = query.where('(project_id IS NULL OR project_id = ?)', project_id) if project_id query = query.where('(project_id IS NULL OR project_id = ?)', project_id) if project_id
if (query.count > 0) if (query.count > 0)
errors.add :key, 'already exist.' errors.add :key, 'already exist.'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment