0

DataMapper を使用して古いデータベースを移行しようとしていますが、多対多の関係で問題が発生しています。

両方とも匿名リソースを通過する and モデルがありますPostTag投稿モデルとタグ モデルではリポジトリ名を設定できますが、自動生成PostTagモデルでは設定できません (私の知る限り)。それらすべてに同じリポジトリ名 ( ) を使用させる方法はあります:legacyか?

乾杯、
トム

4

1 に答える 1

1

次のようなリポジトリ名を定義できるように、「中間」リソースの通常の DM モデルを作成するだけです。

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

これらの親の両方で、 で接続を定義します:through。例えば、

model Post
  # other definitions ...
  has n, :post_tags
  has n, :tags, :through => :post_tags
end
于 2013-03-11T12:27:13.533 に答える