Created
June 30, 2010 02:09
-
-
Save pjb3/458124 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 'dm-core' | |
| require 'dm-migrations' | |
| DataMapper::Logger.new($stdout, :debug) | |
| DataMapper.setup(:default, 'sqlite::memory:') | |
| class AttachmentTag | |
| include DataMapper::Resource | |
| property :id, Serial | |
| belongs_to :attachment | |
| belongs_to :tag | |
| end | |
| class Attachment | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :filename, String | |
| has n, :attachment_tags | |
| has n, :tags, :through => :attachment_tags | |
| end | |
| class Tag | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :tagtext, String | |
| has n, :attachment_tags | |
| has n, :attachments, :through => :attachment_tags | |
| end | |
| DataMapper.auto_migrate! | |
| 10.times do |n| | |
| Tag.create :tagtext => "tag##{n}" | |
| end | |
| 10.times do |n| | |
| a = Attachment.create :filename => "attachment##{n}" | |
| Tag.all.each do |t| | |
| AttachmentTag.create :attachment => a, :tag => t | |
| end | |
| end | |
| Attachment.all.each do |a| | |
| a.attachment_tags.each do |at| | |
| puts "#{a.filename} is tagged with #{at.tag.tagtext}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment