aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-27 17:18:35 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-27 17:18:35 +0000
commit85bb292a8fa95d9685b42b8a131d1f97aa34491c (patch)
tree1071f84cab51c914f7181ef7d2a1c911cf30991c /activerecord
parentea26abeed820d511a8127f4edf06060e3dc129dc (diff)
downloadrails-85bb292a8fa95d9685b42b8a131d1f97aa34491c.tar.gz
rails-85bb292a8fa95d9685b42b8a131d1f97aa34491c.tar.bz2
rails-85bb292a8fa95d9685b42b8a131d1f97aa34491c.zip
Added MacroReflection#macro which will return a symbol describing the macro used (like :composed_of or :has_many) #718, #248 [james@slashetc.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@805 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG5
-rw-r--r--activerecord/lib/active_record/reflection.rb14
-rw-r--r--activerecord/test/reflection_test.rb6
3 files changed, 18 insertions, 7 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 755b3dd9ee..756ed0907b 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,3 +1,8 @@
+*SVN*
+
+* Added MacroReflection#macro which will return a symbol describing the macro used (like :composed_of or :has_many) #718, #248 [james@slashetc.com]
+
+
*1.7.0* (24th February, 2005)
* Changed the auto-timestamping feature to use ActiveRecord::Base.default_timezone instead of entertaining the parallel ActiveRecord::Base.timestamps_gmt method. The latter is now deprecated and will throw a warning on use (but still work) #710 [Jamis Buck]
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 036200a200..55a446ff57 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -10,7 +10,7 @@ module ActiveRecord
def composed_of_with_reflection(part_id, options = {})
composed_of_without_reflection(part_id, options)
- write_inheritable_array "aggregations", [ AggregateReflection.new(part_id, options, self) ]
+ write_inheritable_array "aggregations", [ AggregateReflection.new(:composed_of, part_id, options, self) ]
end
alias_method :composed_of, :composed_of_with_reflection
@@ -24,7 +24,7 @@ module ActiveRecord
def #{association_type}_with_reflection(association_id, options = {})
#{association_type}_without_reflection(association_id, options)
- write_inheritable_array "associations", [ AssociationReflection.new(association_id, options, self) ]
+ write_inheritable_array "associations", [ AssociationReflection.new(:#{association_type}, association_id, options, self) ]
end
alias_method :#{association_type}, :#{association_type}_with_reflection
@@ -67,8 +67,8 @@ module ActiveRecord
# those classes. Objects of AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
class MacroReflection
attr_reader :active_record
- def initialize(name, options, active_record)
- @name, @options, @active_record = name, options, active_record
+ def initialize(macro, name, options, active_record)
+ @macro, @name, @options, @active_record = macro, name, options, active_record
end
# Returns the name of the macro, so it would return :balance for "composed_of :balance, :class_name => 'Money'" or
@@ -77,6 +77,12 @@ module ActiveRecord
@name
end
+ # Returns the name of the macro, so it would return :composed_of for
+ # "composed_of :balance, :class_name => 'Money'" or :has_many for "has_many :clients".
+ def macro
+ @macro
+ end
+
# Returns the hash of options used for the macro, so it would return { :class_name => "Money" } for
# "composed_of :balance, :class_name => 'Money'" or {} for "has_many :clients".
def options
diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb
index aa9b721d97..2842cc34bd 100644
--- a/activerecord/test/reflection_test.rb
+++ b/activerecord/test/reflection_test.rb
@@ -42,11 +42,11 @@ class ReflectionTest < Test::Unit::TestCase
def test_aggregation_reflection
reflection_for_address = ActiveRecord::Reflection::AggregateReflection.new(
- :address, { :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ] }, Customer
+ :composed_of, :address, { :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ] }, Customer
)
reflection_for_balance = ActiveRecord::Reflection::AggregateReflection.new(
- :balance, { :class_name => "Money", :mapping => %w(balance amount) }, Customer
+ :composed_of, :balance, { :class_name => "Money", :mapping => %w(balance amount) }, Customer
)
assert_equal(
@@ -61,7 +61,7 @@ class ReflectionTest < Test::Unit::TestCase
def test_association_reflection
reflection_for_clients = ActiveRecord::Reflection::AssociationReflection.new(
- :clients, { :order => "id", :dependent => true }, Firm
+ :has_many, :clients, { :order => "id", :dependent => true }, Firm
)
assert_equal reflection_for_clients, Firm.reflect_on_association(:clients)