Skip to content

Instantly share code, notes, and snippets.

@solnic
Created October 12, 2010 10:59
Show Gist options
  • Select an option

  • Save solnic/622002 to your computer and use it in GitHub Desktop.

Select an option

Save solnic/622002 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# encoding: utf-8
require 'dm-sqlite-adapter'
require 'dm-migrations'
require 'dm-validations'
DataMapper.setup :default, "sqlite::memory:"
module App
class File
include DataMapper::Resource
property :id, Serial
property :type, Discriminator
property :name, String
belongs_to :folder, :required => false
end
class Folder < File
has n, :files
end
end
DataMapper.finalize
DataMapper.auto_migrate!
file = App::File.new(:name => "foo.txt")
folder = App::Folder.create(:name => "Docs", :files => [file])
puts folder.files.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment