Skip to content

Instantly share code, notes, and snippets.

/a.rb Secret

Created October 27, 2012 03:53
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 anonymous/8f7659b3bd2beb0b485d to your computer and use it in GitHub Desktop.
Save anonymous/8f7659b3bd2beb0b485d to your computer and use it in GitHub Desktop.
class Torrent
include DataMapper::Resource
property :id, Serial
property :name, String
property :magnet, String
property :created_at, DateTime
has n, :tags, :through => Resource
end
class Tag
include DataMapper::Resource
property :id, Serial
property :name, String
property :hits, Integer
has n, :torrents, :through => Resource
end
=begin
# create two resources
torrent = Torrent.create
tag = Tag.create
# link them by adding to the relationship
torrent.tags << tag
torrent.save
# link them by creating the join resource directly
TorrentTag.create(:torrent => torrent, :tag => tag)
# unlink them by destroying the related join resource
link = torrent.torrent_tags.first(:tag => tag)
link.destroy
# unlink them by destroying the join resource directly
link = TorrentTag.get(torrent.id, tag.id)
link.destroy
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment