make uniqueness_of_name validations work again (closes foodcoops/foodsoft#157)
This commit is contained in:
parent
3fd498d29f
commit
5e9a49b2c7
2 changed files with 9 additions and 9 deletions
|
@ -108,13 +108,13 @@ class Ordergroup < Group
|
|||
|
||||
# Make sure, the name is uniq, add usefull message if uniq group is already deleted
|
||||
def uniqueness_of_name
|
||||
id = new_record? ? nil : self.id
|
||||
group = Ordergroup.where('groups.id != ? AND groups.name = ?', id, name).first
|
||||
if group.present?
|
||||
message = group.deleted? ? :taken_with_deleted : :taken
|
||||
group = Ordergroup.where('groups.name = ?', name)
|
||||
group = group.where('groups.id != ?', self.id) unless new_record?
|
||||
if group.exists?
|
||||
message = group.first.deleted? ? :taken_with_deleted : :taken
|
||||
errors.add :name, message
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -82,10 +82,10 @@ class Supplier < ActiveRecord::Base
|
|||
|
||||
# Make sure, the name is uniq, add usefull message if uniq group is already deleted
|
||||
def uniqueness_of_name
|
||||
id = new_record? ? nil : self.id
|
||||
supplier = Supplier.where('suppliers.id != ? AND suppliers.name = ?', id, name).first
|
||||
if supplier.present?
|
||||
message = supplier.deleted? ? :taken_with_deleted : :taken
|
||||
supplier = Supplier.where('suppliers.name = ?', name)
|
||||
supplier = supplier.where('suppliers.id != ?', self.id) unless new_record?
|
||||
if supplier.exists?
|
||||
message = supplier.first.deleted? ? :taken_with_deleted : :taken
|
||||
errors.add :name, message
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue