Skip to content

Instantly share code, notes, and snippets.

@TheNicholasNick
Created January 18, 2009 09:56
Show Gist options
  • Save TheNicholasNick/48589 to your computer and use it in GitHub Desktop.
Save TheNicholasNick/48589 to your computer and use it in GitHub Desktop.
unique properties
#!/usr/bin/env ruby
#
# A one file test to show ...
require 'rubygems'
gem('dm-core', '~> 0.9.8')
require 'dm-core'
require 'dm-validations'
# setup the logger
DataMapper::Logger.new(STDOUT, :debug)
# connect to the DB
DataMapper.setup(:default, 'sqlite3::memory:')
class TestModel
include DataMapper::Resource
# properties
property :id, Serial
property :login, String, :unique_index => :domain
property :domain, String, :unique_index => :domain
validates_is_unique :login, :scope => :domain
end
DataMapper.auto_migrate!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment