Skip to content

Instantly share code, notes, and snippets.

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
class Entity
include DataMapper::Resource
property :id, Serial
property :name, String
property :type, Discriminator
class Book < Entity
property :title, String
has n, :authors, :through => Resource
class Author < Entity
property :name, String
has n, :books, :through => Resource
#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