diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 8831c64815ac0..bba5fd93c3c6c 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed issue that kept :select options from being scoped [Rick] + * Fixed db_schema_import when binary types are present #3101 [DHH] * Fixed that MySQL enums should always be returned as strings #3501 [DHH] diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 104ed5ba58c3b..dafae89861fa8 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -106,7 +106,7 @@ def construct_joins(custom_joins = nil) def construct_scope { - :find => { :from => construct_from, :conditions => construct_conditions, :joins => construct_joins }, + :find => { :from => construct_from, :conditions => construct_conditions, :joins => construct_joins, :select => construct_select }, :create => { @reflection.primary_key_name => @owner.id } } end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index facb22c0e902a..c58a7bf5c24d5 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -873,7 +873,7 @@ def with_scope(method_scoping = {}, action = :merge, &block) method_scoping.assert_valid_keys([ :find, :create ]) if f = method_scoping[:find] - f.assert_valid_keys([ :conditions, :joins, :from, :offset, :limit, :readonly ]) + f.assert_valid_keys([ :conditions, :joins, :select, :from, :offset, :limit, :readonly ]) f[:readonly] = true if !f[:joins].blank? && !f.has_key?(:readonly) end @@ -980,7 +980,7 @@ def type_name_with_module(type_name) end def construct_finder_sql(options) - sql = "SELECT #{options[:select] || '*'} " + sql = "SELECT #{scope(:find, :select) || options[:select] || '*'} " sql << "FROM #{scope(:find, :from) || options[:from] || table_name} " add_joins!(sql, options) diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb index 08b460995e167..5f8ac7e0c0816 100644 --- a/activerecord/test/associations_join_model_test.rb +++ b/activerecord/test/associations_join_model_test.rb @@ -316,6 +316,10 @@ def test_add_to_self_referential_has_many_through assert_equal new_author, authors(:david).reload.favorite_authors.first end + def test_has_many_through_uses_correct_attributes + assert_nil posts(:thinking).tags.find_by_name("General").attributes["tag_id"] + end + private # create dynamic Post models to allow different dependency options def find_post_with_dependency(post_id, association, association_name, dependency)