Created
April 18, 2011 07:41
-
-
Save jasmarc/924956 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'datamapper' | |
require 'pp' | |
class Author | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
has n, :entries, :through => Resource | |
has n, :friendships, :child_key => [ :source_id ] | |
has n, :friends, self, :through => :friendships, :via => :target | |
end | |
class Friendship | |
include DataMapper::Resource | |
belongs_to :source, 'Author', :key => true | |
belongs_to :target, 'Author', :key => true | |
end | |
class Entry | |
include DataMapper::Resource | |
property :id , Serial | |
property :abstractText , String | |
property :author , String | |
property :booktitle , String | |
property :entry , String | |
property :indexNumber , String | |
property :isbn , String | |
property :pages , String | |
property :publisher , String | |
property :referenceIndexNumbers, String | |
property :title , String | |
property :url , String | |
property :year , String | |
property :isSeed , Boolean, :default => false | |
property :type , String | |
has n, :authors, :through => Resource | |
end | |
DataMapper.finalize | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'mysql://xxx:[email protected]/ICSSND') | |
a = Author.get(16).friends | |
a.each do |author| | |
puts author.id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment