0

I'm trying to migrate an old database using DataMapper and I am having an issue with a many to many relation.

I have a Post and Tag model that both go through an anonymous resource. I can set the repository name in the post and tag models, but not the auto-generated PostTag model (as far as I know). Is there a way to make all of them use the same repository name (:legacy)?

Cheers,
Tom

Tom Brunoli
  • 3,436
  • 9
  • 36
  • 54

1 Answers1

1

You can just create a normal DM model for the "middle" resource to be able to define the repository name, such as

model PostTag
  include DataMapper::Resource
  def self.default_repository_name; :legacy end
  belongs_to :post, :key => true
  belongs_to :tag, :key => true
end

and in both of those parents, define the connection with a :through. For example,

model Post
  # other definitions ...
  has n, :post_tags
  has n, :tags, :through => :post_tags
end
morbusg
  • 1,319
  • 2
  • 11
  • 20