Skip to content

Commit

Permalink
Fix problems with cache_classes == false on certain server configurat…
Browse files Browse the repository at this point in the history
…ions. Also handle self-join with a merge of two identical classes and a second param.
  • Loading branch information
Ernie Miller committed Aug 3, 2010
1 parent 76f139f commit ee84185
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/meta_where/relation.rb
Expand Up @@ -13,9 +13,9 @@ module Relation
end

def merge_with_metawhere(r, association_name = nil)
if (r && klass != r.klass) # Merging relations with different base.
default_association = reflect_on_all_associations.detect {|a| a.klass == r.klass}
association_name ||= default_association ? default_association.name : r.table_name.to_sym
if (r && (association_name || klass.name != r.klass.name)) # Merging relations with different base.
association_name ||= (default_association = reflect_on_all_associations.detect {|a| a.klass.name == r.klass.name}) ?
default_association.name : r.table_name.to_sym
r = r.clone
r.where_values.map! {|w| w.respond_to?(:to_predicate) ? {association_name => w} : w}
r.joins_values.map! {|j| [Symbol, Hash].include?(j.class) ? {association_name => j} : j}
Expand Down

0 comments on commit ee84185

Please sign in to comment.