0

I'm using DataMapper with the redis adapter in a Ruby library.

I have these classes defined:

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

and

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

I'm able to do Campaign.first.zone but not Zone.first.campaign.

I would like to be able to do the lookups in both directions.

lightyrs
  • 2,620
  • 2
  • 26
  • 31
  • Your code seems to be working here. What is the error you're getting? – Adiel Mittmann Apr 15 '12 at 00:42
  • @AdielMittmann — There is no error, however, the code is not behaving how I expect. I would like to be able to look up a child from a parent as well as a parent from a child. Currently, only child to parent lookups are working with this configuration. – lightyrs Apr 15 '12 at 19:30
  • But what happens when you do something like `puts Zone.first.campaign.name`? After creating a zone and a campaign, in my setup this piece of code does the lookup as expected :) – Adiel Mittmann Apr 15 '12 at 19:33
  • @AdielMittmann Yea, I should've been clearer. This is happening even after explicitly loading child properties as in your example. – lightyrs Apr 15 '12 at 19:37
  • @AdielMittmann I think it is an issue with the way dm-redis-adapter handles non-serial primary keys. – lightyrs Apr 15 '12 at 19:37

1 Answers1

1

@lightyrs I responded to your github issue, but for reference here, I think this issue has been fixed in versions > 0.8 that have better support for non-serial primary keys.

Cheers! - whoahbot

whoahbot
  • 26
  • 3