Skip to content

Instantly share code, notes, and snippets.

@foxiepaws
Created October 9, 2015 02:57
Show Gist options
  • Select an option

  • Save foxiepaws/491d773a8fadad712dfa to your computer and use it in GitHub Desktop.

Select an option

Save foxiepaws/491d773a8fadad712dfa to your computer and use it in GitHub Desktop.
require 'datamapper'
class Book
include DataMapper::Resource
property :id, Serial
property :title, String
property :summary, Text
# associations to other models
belongs_to :author
has n, :taggings
has n, :tags, :through => :taggings
# TODO: write functions to make editlog work.
has n, :editlog
end
class Trope
include DataMapper::Resource
property :id, Serial
property :name, String
property :desc, Text
end
class TropeSpoiler
include DataMapper::Resource
property :id, Serial
# tropeid
property :spoiler, Text
end
class Author
include DataMapper::Resource
property :id, Serial
property :name, String
property :bio, Text
has n, :books
end
class Tags
include DataMapper::Resource
property :id, Serial
property :tag, String
has n, :taggings
has n, :books, :through => taggings
end
class Taggings
include DataMapper::Resource
belongs_to :tag, :key => true
belongs_to :book, :key => true
end
class EditLog
include DataMapper::Resource
property :id, Serial
property :type, Integer # 0 is creation, 1 is modified, 2 is deletion
# association for who made this.
property :time, DateTime
property :minor, Boolean, :default => true
property :desc, Text #
property :diff, Text # content of
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment