Skip to content

Instantly share code, notes, and snippets.

@outoftime
Forked from anonymous/airmigos
Created February 27, 2009 03:21
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 outoftime/71264 to your computer and use it in GitHub Desktop.
Save outoftime/71264 to your computer and use it in GitHub Desktop.
class Airmigo
include DataMapper::Resource
property :id, Serial
belongs_to :from, :class_name => 'User'
belongs_to :to, :class_name => 'User'
before :save do
Airmigo.first_or_create(:conditions => { :from => to, :to => from })
end
before :destroy do
Airmigo.destroy(:from => to, :to => from)
end
end
# This is a default user class used to activate merb-auth. Feel free to change from a User to
# Some other class, or to remove it altogether. If removed, merb-auth may not work by default.
#
# Don't forget that by default the salted_user mixin is used from merb-more
# You'll need to setup your db as per the salted_user mixin, and you'll need
# To use :password, and :password_confirmation when creating a user
#
# see merb/merb-auth/setup.rb to see how to disable the salted_user mixin
#
# You will need to setup your database and create a user.
class User
include DataMapper::Resource
property :id, Serial
property :updated_at, DateTime
property :login, String, :nullable => false
property :firstname, String
property :lastname, String
has n, :emails
has n, :localairports
has n, :airmigos, :as => :from, :dependent => :destroy
has n, :airmigos_to_self, :as => :to, :dependent => :destroy # just there for referential integrity
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment