Permalink
Browse files

fix nil options bug; make it easy to debug string that's class eval'ed

  • Loading branch information...
1 parent 8d5e96a commit 3759bc8820b36dfb0157da0ba6f5c1b1ca000831 @jackdempsey committed Dec 7, 2008
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/sequel_polymorphic/sequel_polymorphic.rb
@@ -12,6 +12,7 @@ module InstanceMethods
module ClassMethods
def many_to_one(*args, &block)
able, options = *args
+ options ||= {}
if options[:polymorphic]
model = self.class.to_s.downcase
plural_model = model.pluralize
@@ -52,7 +53,7 @@ def one_to_many(*args, &block)
one_to_many_variable, options = *args
many_class = one_to_many_variable.to_s.singularize
if able = options[:as]
- self.class_eval %{
+ method_definitions = %{
associate(:one_to_many, :#{one_to_many_variable}, :key=>:#{able}_id) do |ds|
ds.filter(:#{able}_type=>'#{self}')
end
@@ -73,6 +74,7 @@ def _remove_all_#{one_to_many_variable}
#{many_class.capitalize}.filter(:#{able}_id=>pk, :#{able}_type=>'#{self}').update(:#{able}_id=>nil, :#{able}_type=>nil)
end
}
+ self.class_eval method_definitions
else
associate(:one_to_many, *args, &block)
end

0 comments on commit 3759bc8

Please sign in to comment.