Skip to content

Instantly share code, notes, and snippets.

@adamhunter
Created May 27, 2011 13:44
Show Gist options
  • Save adamhunter/995278 to your computer and use it in GitHub Desktop.
Save adamhunter/995278 to your computer and use it in GitHub Desktop.
require 'ripple/associations/proxy'
require 'ripple/associations/one'
module Ripple
module Associations
class OneKeyProxy < Proxy
include One
def replace(doc)
@reflection.verify_type!(doc, owner)
doc.key = owner.key
owner.class.__send__(:define_method, "key=") do |value|
doc.key = value unless doc.key == value
super(value) unless key == value
end
loaded
@target = doc
end
def find_target
klass.find(owner.key)
end
protected
def instantiate_target(instantiator, attrs={})
@target = super
@target.key = owner.key
@target
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment