Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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