开发者

Can DataMapper properties appear in multiple composite indexes?

I found that this issue had been discussed in Ticket #58 of DataMapper, apparently way back in 2007, but I can't find how to do it in the latest version (dm-core-0.10.2). I want to define two composite indexes, each of which are partially based on a certain property. I was hoping I could do this...

class Stat
  include DataMapper::Resource
  property :id,            Serial,
  property :collected_on,  Integer #yyyyMMddhhmm
  property :measu开发者_如何学JAVAre,       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

What is the correct way to do it?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜