私はこのページをかなり徹底的に読みました:
http://datamapper.org/docs/associations
そこに答えがあるとすれば、それは私が理解できる方法で表現されていないだけです。
Datamapper を介して関係を設定する方法について非常に混乱しています。上記のデータマッパーのサイトは、このトピックに関して私が見つけることができるほとんどすべてであり、私が言ったように、特に役に立ちませんでした.
たとえば、次のようなものを作成したい場合:
テーブル:users
id (primary key)
name
テーブル:attributes
id (pk)
title
テーブル:user_attributes
id (pk)
user_id (fk to users.id)
attribute_id (fk to attributes.id)
value
これは簡単そうに見えますが、非常に難しいものです。私が試してみると、次のようなエラーが発生しますNo relationships named user_attributes or user_attribute in UserUserAttribute (DataMapper::UnknownRelationshipError)
この単純なマッピングのクラス定義を教えてください。おそらく、DataMapper 関連付けのより良い議論を教えてもらえますか? 以下は、私が試したことの一部です。
class User
include DataMapper::Resource
property :id, Serial, :key => true
property :name, String
has n, :user_attributes, :through=>:attribute
end
class Attribute
include DataMapper::Resource
property :id, Serial, :key => true
property :name, String
has n, :user_attributes, :through=>:user
end
class UserAttribute
include DataMapper::Resource
belongs_to :user
belongs_to :attribute
end