check uniqueness for item, layout and snippet

This commit is contained in:
Wen-Tien Chang 2010-02-05 17:04:07 +08:00
parent 3d6446041b
commit e11dc5dd83
3 changed files with 5 additions and 1 deletions

View File

@ -15,6 +15,8 @@ class Item
key :is_published, Boolean, :required => true, :default => true, :index => true
validates_format_of :name, :with => /^[a-zA-Z-_]+$/
validates_uniqueness_of :name
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
many :children, :class_name => "Item", :foreign_key => :parent_id, :dependent => :destroy

View File

@ -9,5 +9,6 @@ class Layout
many :children, :class_name => "Item", :foreign_key => "layout_id", :dependent => :nullify
validates_format_of :name, :with => /^[a-zA-Z-_]+$/
validates_uniqueness_of :name
end

View File

@ -4,11 +4,12 @@ class Snippet
key :name, String, :required => true, :index => true
key :parent_name, String, :required => true, :index => true
key :parent_id, String, :required => true, :index => true
key :parent_id, ObjectId, :required => true, :index => true
key_i18n :content, String
before_validation :setup_default_value
validates_uniqueness_of :name, :scope => :parent_id
protected