0
我在Ruby庫中使用Redis適配器中的DataMapper。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。
我希望能夠在兩個方向進行查找。
你的代碼似乎在這裏工作。你得到的錯誤是什麼? – 2012-04-15 00:42:19
@AdielMittmann - 然而,沒有錯誤,代碼沒有如我所期望的那樣行事。我希望能夠從父母以及孩子的父母那裏查找孩子。目前,只有子級到父級查找正在使用此配置。 – lightyrs 2012-04-15 19:30:49
但是當你做'puts Zone.first.campaign.name'時會發生什麼?在創建一個區域和一個活動之後,在我的設置中,這段代碼按照預期進行查找:) – 2012-04-15 19:33:45