Permalink
Browse files

self is an instance inside the block (must be instance_eval'ed), so m…

…ake sure to use self.class
  • Loading branch information...
1 parent 118bec3 commit c5611647cac50d7f73f91806ec79c0402a974f72 @jackdempsey committed Dec 8, 2008
Showing with 4 additions and 3 deletions.
  1. +4 −3 lib/sequel_polymorphic/sequel_polymorphic.rb
@@ -55,7 +55,7 @@ def one_to_many(*args, &block)
many_class = many_of_class.to_s.singularize
if able = options[:as]
associate(:one_to_many, many_of_class, :key=>"#{able}_id".to_sym) do |ds|
- ds.filter("#{able}_type".to_sym=>self.to_s)
+ ds.filter("#{able}_type".to_sym => self.class.to_s)
end
method_definitions = %{
@@ -88,11 +88,12 @@ def many_to_many(*args, &block)
many_to_class, options = *args # => :tags, :through => :taggings, :as => :taggable
many_class = many_to_class.to_s.singularize # => tag
options ||= {}
- if through = options[:through] and able = options[:as]
+ if through = (options[:through] or options[:join_table]) and able = options[:as]
through_klass = through.to_s.singularize.capitalize # => Tagging
+ # self in the block passed to associate is an instance of the class, hence the self.class call
associate(:many_to_many, many_to_class,
:left_key => "#{able}_id".to_sym,
- :join_table => through) { |ds| ds.filter("#{able}_type".to_sym=>self.to_s) }
+ :join_table => through) { |ds| ds.filter("#{able}_type".to_sym => self.class.to_s) }
method_string = %{
private

0 comments on commit c561164

Please sign in to comment.