Skip to content
Browse files

Use reflection to determine table name rather than the through option…

…. More reliable
  • Loading branch information...
1 parent f86a7de commit 3ec07b53d8e6b7475f8409d97de71f0762be56eb @jstewart committed
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/is_paranoid.rb
View
5 lib/is_paranoid.rb
@@ -42,8 +42,9 @@ def is_or_equals_not_destroyed
# ensure that we respect the is_paranoid conditions when being loaded as a has_many :through
# NOTE: this only works if is_paranoid is declared before has_many relationships.
def has_many(association_id, options = {}, &extension)
- if options.key?(:through)
- conditions = "#{options[:through].to_s.pluralize}.#{destroyed_field} #{is_or_equals_not_destroyed}"
+ if options.key?(:through)
+ _table_name = self.reflect_on_association(options[:through]).table_name
+ conditions = "#{_table_name}.#{destroyed_field} #{is_or_equals_not_destroyed}"
options[:conditions] = "(" + [options[:conditions], conditions].compact.join(") AND (") + ")"
end
super

0 comments on commit 3ec07b5

Please sign in to comment.
Something went wrong with that request. Please try again.