-
-
Save anonymous/8f7659b3bd2beb0b485d to your computer and use it in GitHub Desktop.
This file contains 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
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