aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorRodrigo Kochenburger <divoxx@gmail.com>2008-04-11 12:35:09 -0300
committerrick <technoweenie@gmail.com>2008-05-13 15:04:11 -0700
commitbca8751e40a5594c4de2ca58e089b8d98e44632b (patch)
tree34a89b57cdf2ac2092c103975eeb2fa0f51c03e8 /activerecord/lib/active_record/base.rb
parent2d372d704987e05712ccd937e78d8dbd41242efe (diff)
downloadrails-bca8751e40a5594c4de2ca58e089b8d98e44632b.tar.gz
rails-bca8751e40a5594c4de2ca58e089b8d98e44632b.tar.bz2
rails-bca8751e40a5594c4de2ca58e089b8d98e44632b.zip
Add ActiveRecord option to store the full class name on STI's type column, allowing one to have STI subclasses in different namespaces [#114]
Signed-off-by: rick <technoweenie@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 392d187092..ac1a35dc91 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -439,6 +439,10 @@ module ActiveRecord #:nodoc:
cattr_accessor :schema_format , :instance_writer => false
@@schema_format = :ruby
+ # Determine whether to store the full constant name including namespace when using STI
+ superclass_delegating_accessor :store_full_sti_class
+ self.store_full_sti_class = false
+
class << self # Class methods
# Find operates with four different retrieval approaches:
#
@@ -1557,8 +1561,8 @@ module ActiveRecord #:nodoc:
def type_condition
quoted_inheritance_column = connection.quote_column_name(inheritance_column)
- type_condition = subclasses.inject("#{quoted_table_name}.#{quoted_inheritance_column} = '#{name.demodulize}' ") do |condition, subclass|
- condition << "OR #{quoted_table_name}.#{quoted_inheritance_column} = '#{subclass.name.demodulize}' "
+ type_condition = subclasses.inject("#{quoted_table_name}.#{quoted_inheritance_column} = '#{store_full_sti_class ? name : name.demodulize}' ") do |condition, subclass|
+ condition << "OR #{quoted_table_name}.#{quoted_inheritance_column} = '#{store_full_sti_class ? subclass.name : subclass.name.demodulize}' "
end
" (#{type_condition}) "
@@ -2492,7 +2496,7 @@ module ActiveRecord #:nodoc:
# Message class in that example.
def ensure_proper_type
unless self.class.descends_from_active_record?
- write_attribute(self.class.inheritance_column, Inflector.demodulize(self.class.name))
+ write_attribute(self.class.inheritance_column, store_full_sti_class ? self.class.name : Inflector.demodulize(self.class.name))
end
end