diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-27 05:41:23 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-27 05:41:23 +0000 |
commit | b5ba377b784c58db7b7fb878862a550ae57beb95 (patch) | |
tree | fdd554b5d3a534290272271f8ae710fa1b30f61b /activerecord | |
parent | e567a5eb1afe1ac38f1da37f1c1e3922bbf79d2a (diff) | |
download | rails-b5ba377b784c58db7b7fb878862a550ae57beb95.tar.gz rails-b5ba377b784c58db7b7fb878862a550ae57beb95.tar.bz2 rails-b5ba377b784c58db7b7fb878862a550ae57beb95.zip |
Added option to Base.reflection_of_all_associations to specify a specific association to scope the call. For example Base.reflection_of_all_associations(:has_many) [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3357 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 8 | ||||
-rw-r--r-- | activerecord/test/reflection_test.rb | 6 |
3 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 9374c487af..bdd384bb3a 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added option to Base.reflection_of_all_associations to specify a specific association to scope the call. For example Base.reflection_of_all_associations(:has_many) [DHH] + * Added ActiveRecord::SchemaDumper.ignore_tables which tells SchemaDumper which tables to ignore. Useful for tables with funky column like the ones required for tsearch2. [TobiasLuetke] * SchemaDumper now doesn't fail anymore when there are unknown column types in the schema. Instead the table is ignored and a Comment is left in the schema.rb. [TobiasLuetke] diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 87a05086fc..9bac82f5ce 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -34,9 +34,11 @@ module ActiveRecord reflections[aggregation].is_a?(AggregateReflection) ? reflections[aggregation] : nil end - # Returns an array of AssociationReflection objects for all the aggregations in the class. - def reflect_on_all_associations - reflections.values.select { |reflection| reflection.is_a?(AssociationReflection) } + # Returns an array of AssociationReflection objects for all the aggregations in the class. If you only want to reflect on a + # certain association type, pass in the symbol for that as the first parameter. + def reflect_on_all_associations(macro = nil) + association_reflections = reflections.values.select { |reflection| reflection.is_a?(AssociationReflection) } + macro ? association_reflections.select { |reflection| reflection.macro == macro } : association_reflections end # Returns the AssociationReflection object for the named +aggregation+ (use the symbol). Example: diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb index 7af9e8c70d..09da3e5986 100644 --- a/activerecord/test/reflection_test.rb +++ b/activerecord/test/reflection_test.rb @@ -93,4 +93,10 @@ class ReflectionTest < Test::Unit::TestCase assert_equal MyApplication::Business::Client, MyApplication::Business::Firm.reflect_on_association(:clients_of_firm).klass assert_equal MyApplication::Business::Firm, MyApplication::Billing::Account.reflect_on_association(:firm).klass end + + def test_reflection_of_all_associations + assert_equal 12, Firm.reflect_on_all_associations.size + assert_equal 11, Firm.reflect_on_all_associations(:has_many).size + assert_equal 1, Firm.reflect_on_all_associations(:has_one).size + end end |