Skip to content

Instantly share code, notes, and snippets.

@lobo-tuerto
Created October 2, 2008 17:52
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 lobo-tuerto/14409 to your computer and use it in GitHub Desktop.
Save lobo-tuerto/14409 to your computer and use it in GitHub Desktop.
# Right now if you do this and run rake db:automigrate (I'm using postgresql)
# it will generate a table called authors_books with one column called entity_id
# instead of adding 2 columns to the table (book_id, author_id).
#
# I think that means it is getting and using the parent model from the STI hierarchy
# This was an attempt to patch it up, it's working but it's breaking one spec
# http://github.com/lobo-tuerto/dm-core/commit/c2103bc1789c05685fb111194635fa13f5707ea9
class Entity
include DataMapper::Resource
property :id, Serial
property :name, String
property :type, Discriminator
end
class Book < Entity
property :title, String
has n, :authors, :through => Resource
end
class Author < Entity
property :name, String
has n, :books, :through => Resource
end
#This is the result
CREATE TABLE authors_books
(
entity_id integer NOT NULL,
CONSTRAINT authors_books_pkey PRIMARY KEY (entity_id)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment