我在 Ruby 库中使用 DataMapper 和 redis 适配器。
我定义了这些类:
class Zone
include DataMapper::Resource
property :id, String, :key => true, :unique_index => true, :default => lambda { |x,y| UUID.new.generate }
property :preview_mode, Boolean, :default => false
timestamps :at
has 1, :campaign
end
和
class Campaign
include DataMapper::Resource
property :id, String, :key => true, :unique_index => true, :default => lambda { |x,y| UUID.new.generate }
property :name, String
timestamps :at
belongs_to :zone
has n, :rules
validates_presence_of :name
end
我可以做 Campaign.first.zone 但不能做 Zone.first.campaign。
我希望能够在两个方向上进行查找。