Skip to content

Commit

Permalink
self is an instance inside the block (must be instance_eval'ed), so m…
Browse files Browse the repository at this point in the history
…ake sure to use self.class
  • Loading branch information
jackdempsey committed Dec 8, 2008
1 parent 118bec3 commit c561164
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/sequel_polymorphic/sequel_polymorphic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = %{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c561164

Please sign in to comment.