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
|
# Make sure, the name is uniq, add usefull message if uniq group is already deleted
|
||||||
def uniqueness_of_name
|
def uniqueness_of_name
|
||||||
id = new_record? ? nil : self.id
|
group = Ordergroup.where('groups.name = ?', name)
|
||||||
group = Ordergroup.where('groups.id != ? AND groups.name = ?', id, name).first
|
group = group.where('groups.id != ?', self.id) unless new_record?
|
||||||
if group.present?
|
if group.exists?
|
||||||
message = group.deleted? ? :taken_with_deleted : :taken
|
message = group.first.deleted? ? :taken_with_deleted : :taken
|
||||||
errors.add :name, message
|
errors.add :name, message
|
||||||
end
|
end
|
||||||
end
|
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
|
# Make sure, the name is uniq, add usefull message if uniq group is already deleted
|
||||||
def uniqueness_of_name
|
def uniqueness_of_name
|
||||||
id = new_record? ? nil : self.id
|
supplier = Supplier.where('suppliers.name = ?', name)
|
||||||
supplier = Supplier.where('suppliers.id != ? AND suppliers.name = ?', id, name).first
|
supplier = supplier.where('suppliers.id != ?', self.id) unless new_record?
|
||||||
if supplier.present?
|
if supplier.exists?
|
||||||
message = supplier.deleted? ? :taken_with_deleted : :taken
|
message = supplier.first.deleted? ? :taken_with_deleted : :taken
|
||||||
errors.add :name, message
|
errors.add :name, message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue