diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-01-14 17:53:52 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-01-16 21:17:17 +0000 |
commit | ee7f66603573fd441f1522cc73ec0b7f56c4d1af (patch) | |
tree | 5eb727b65af37d296425bfbb0412786d55d01e10 /activerecord/lib/active_record/relation | |
parent | 4429f16c0ada896fe3753324f0201b290c6425d9 (diff) | |
download | rails-ee7f66603573fd441f1522cc73ec0b7f56c4d1af.tar.gz rails-ee7f66603573fd441f1522cc73ec0b7f56c4d1af.tar.bz2 rails-ee7f66603573fd441f1522cc73ec0b7f56c4d1af.zip |
automatically add references when we can
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 4 |
2 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 88081edae2..1d04e763f6 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -21,6 +21,18 @@ module ActiveRecord predicates.flatten end + def self.references(attributes) + references = attributes.map do |key, value| + if value.is_a?(Hash) + key + else + key = key.to_s + key.split('.').first.to_sym if key.include?('.') + end + end + references.compact + end + private def self.build(attribute, value) case value diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 7b340c1b64..ef3545c76a 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -52,7 +52,7 @@ module ActiveRecord return self if args.blank? relation = clone - relation.references_values = (references_values + args).uniq + relation.references_values = (references_values + args).flatten.uniq relation end @@ -151,6 +151,7 @@ module ActiveRecord return self if opts.blank? relation = clone + relation = relation.references(PredicateBuilder.references(opts)) if Hash === opts relation.where_values += build_where(opts, rest) relation end @@ -159,6 +160,7 @@ module ActiveRecord return self if opts.blank? relation = clone + relation = relation.references(PredicateBuilder.references(opts)) if Hash === opts relation.having_values += build_where(opts, rest) relation end |