From 9af99ad5af26c95942965b79c47c9b4605daf22a Mon Sep 17 00:00:00 2001 From: Michael Solovyov Date: Fri, 21 Oct 2011 20:12:31 -0700 Subject: [PATCH] custom belongs_to not taking into account foreign key fix --- lib/simply_stored/couch/has_many.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/simply_stored/couch/has_many.rb b/lib/simply_stored/couch/has_many.rb index 8ad047e..c9ef914 100644 --- a/lib/simply_stored/couch/has_many.rb +++ b/lib/simply_stored/couch/has_many.rb @@ -61,7 +61,11 @@ def define_has_many_setter_add(name, options) klass = self.class.get_class_from_name(name) raise ArgumentError, "expected #{klass} got #{value.class}" unless value.is_a?(klass) - value.send("#{self.class.foreign_key}=", id) + if !options[:foreign_key].blank? + value.send("#{options[:foreign_key]}=", id) + else + value.send("#{self.class.foreign_key}=", id) + end value.save(false) cached_results = send("_get_cached_#{name}")[:all]