3

我发现这个问题已经在 DataMapper 的Ticket #58中讨论过,显然早在 2007 年,但我在最新版本 (dm-core-0.10.2) 中找不到如何解决。我想定义两个复合索引,每个索引都部分基于某个属性。我希望我能做到这一点...

class Stat
  include DataMapper::Resource
  property :id,            Serial,
  property :collected_on,  Integer #yyyyMMddhhmm
  property :measure,       Integer
  property :dimension_one, Integer
  property :dimension_two, Integer
  property :source_id,     Integer
  index [:collected_on, :dimension_one, :dimension_two]
  index [:source_id, :collected_on]
end

正确的方法是什么?

4

1 回答 1

2

You can do this:

class Stat
  include DataMapper::Resource
  property :id,            Serial,
  property :collected_on,  Integer, :index => [ :index_one, :index_two ]
  property :measure,       Integer
  property :dimension_one, Integer, :index => :index_one
  property :dimension_two, Integer, :index => :index_one
  property :source_id,     Integer, :index => :index_two
end

Of course you can make the indexes anything you like. The indexes can be an Array, or a Symbol as shown above, or even just true if you want to put the property in an index by itself and you don't care what the index is called.

于 2010-02-04T11:26:39.033 回答