Skip to content

Instantly share code, notes, and snippets.

@aleksclark
Created August 19, 2011 16:10
Show Gist options
  • Save aleksclark/1157210 to your computer and use it in GitHub Desktop.
Save aleksclark/1157210 to your computer and use it in GitHub Desktop.
Sinatra-authentication has n, bug
require 'sinatra'
require "digest/sha1"
require 'rack-flash'
require "dm-core"
#for using auto_migrate!
require "dm-migrations"
require "sinatra/reloader"
require 'haml'
require "sinatra-authentication"
use Rack::Session::Cookie, :secret => 'A1 sauce 1s on a11 yr s'
#if you want flash messages
use Rack::Flash
DataMapper.setup( :default, "sqlite3://#{Dir.pwd}/test.db" )
class DmUser
# include DataMapper::Resource
property :name, String
# property :id, Serial, :key => true
has n, :things
end
class Thing
include DataMapper::Resource
property :name, String, :key => true
belongs_to :dm_user
end
DataMapper.finalize
DataMapper.auto_migrate!
bob = DmUser.create(:name => "bob", :email => "[email protected]")
bob.save!
Thing.create(:name => "green thing", :dm_user_id => bob.id)
#this works
Thing.first.dm_user
#this does not
DmUser.first.things
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment