Skip to content

Instantly share code, notes, and snippets.

@slaskis
Created October 13, 2009 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaskis/209257 to your computer and use it in GitHub Desktop.
Save slaskis/209257 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
class Event
include DataMapper::Resource
default_scope.update( :order => [ :start_time.desc ] )
property :id, Serial
property :eid, String
property :name, String, :length => 255
property :tagline, String, :length => 255
property :start_time, Integer
property :end_time, Integer
property :location, String, :length => 255
property :description, Text
end
DataMapper::Logger.new(STDOUT)
DataMapper.setup(:default, "sqlite3::memory:")
DataMapper.auto_migrate!
Event.create( :eid => "abc" )
Event.create( :eid => "def" )
Event.create( :eid => "abc" )
p Event.all( :fields => [:eid] , :unique => true )
# => TypeError: can't modify frozen object
p Event.all( :fields => [:id,:eid] , :unique => true )
# Works!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment