Datamapperでは、2つのフィールドの組み合わせが一意である必要があることをどのように指定しますか。たとえば、カテゴリにはドメイン内で一意の名前を付ける必要があります。
class Category
include DataMapper.resource
property :name, String, :index=>true #must be unique for a given domain
belongs_to :domain
end
Datamapperでは、2つのフィールドの組み合わせが一意である必要があることをどのように指定しますか。たとえば、カテゴリにはドメイン内で一意の名前を付ける必要があります。
class Category
include DataMapper.resource
property :name, String, :index=>true #must be unique for a given domain
belongs_to :domain
end
2つのプロパティに一意のインデックスを作成する必要があります。
class Category
include DataMapper::Resource
property :name, String, :unique_index => :u
property :domain_id, Integer, :unique_index => :u
belongs_to :domain
end
実際、John、Joschiの答えは正しいです。名前付き:unique_index値を使用すると、複数列のインデックスが作成されます。それらのハッシュロケットの右側を読むことが重要です(つまり、それがちょうどだった場合true
、あなたは正しいでしょう)。
両方のプロパティをキーとして定義しようとしましたか?試したかどうかはわかりませんが、そうすれば複合キーになるはずです。
property :name, String, :key => true
property :category, Integer, :key => true