Skip to content

Loading…

Fix for not taking into account class_name in custom has_many #19

Open
wants to merge 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/simply_stored/couch/has_many.rb
View
6 lib/simply_stored/couch/has_many.rb
@@ -58,7 +58,11 @@ def define_has_many_through_getter(name, options, through)
def define_has_many_setter_add(name, options)
define_method("add_#{name.to_s.singularize}") do |value|
- klass = self.class.get_class_from_name(name)
+ if !options[:class_name].blank?
+ klass = self.class.get_class_from_name(options[:class_name])
+ else
+ klass = self.class.get_class_from_name(name)
+ end
raise ArgumentError, "expected #{klass} got #{value.class}" unless value.is_a?(klass)
value.send("#{self.class.foreign_key}=", id)
Something went wrong with that request. Please try again.