Skip to content

Instantly share code, notes, and snippets.

@pathsny
Created November 26, 2010 12:18
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 pathsny/716637 to your computer and use it in GitHub Desktop.
Save pathsny/716637 to your computer and use it in GitHub Desktop.
class Pet
include DataMapper::Resource
property :id, Serial
property :name, String
property :type, Discriminator, :required => true, :index => true
end
class Dog < Pet
end
class Human
include DataMapper::Resource
property :id, Serial
has n, :pets
end
DataMapper.finalize
h = Human.new(:pets => [Pet.new(:name => "nemo"), Dog.new(:name => "fido")])
h.pets.first(:type => Dog) # => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment