diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-24 03:36:48 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-24 03:36:48 +0000 |
commit | 4b4dd5408228c342f36bfd8290d39de2cf7bbd71 (patch) | |
tree | 0466f73aa20813cdec2ca3c08ce73ac8f1458631 /activerecord/lib | |
parent | d65a8f6e9ee5b2c0d81a61983649bd8c431ca4d4 (diff) | |
download | rails-4b4dd5408228c342f36bfd8290d39de2cf7bbd71.tar.gz rails-4b4dd5408228c342f36bfd8290d39de2cf7bbd71.tar.bz2 rails-4b4dd5408228c342f36bfd8290d39de2cf7bbd71.zip |
Clashing type columns due to a sloppy join shouldn't wreck single-table inheritance. Closes #5838.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4813 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index d3a8abd016..d98629e289 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1027,23 +1027,34 @@ module ActiveRecord #:nodoc: end end - # Finder methods must instantiate through this method to work with the single-table inheritance model - # that makes it possible to create objects of different types from the same table. + # Finder methods must instantiate through this method to work with the + # single-table inheritance model that makes it possible to create + # objects of different types from the same table. def instantiate(record) - object = + object = if subclass_name = record[inheritance_column] + # No type given. if subclass_name.empty? allocate + else require_association_class(subclass_name) - begin - compute_type(subclass_name).allocate - rescue NameError - raise SubclassNotFound, - "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " + - "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " + - "Please rename this column if you didn't intend it to be used for storing the inheritance class " + - "or overwrite #{self.to_s}.inheritance_column to use another column for that information." + + # Ignore type if no column is present since it was probably + # pulled in from a sloppy join. + unless self.columns_hash.include?(inheritance_column) + allocate + + else + begin + compute_type(subclass_name).allocate + rescue NameError + raise SubclassNotFound, + "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " + + "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " + + "Please rename this column if you didn't intend it to be used for storing the inheritance class " + + "or overwrite #{self.to_s}.inheritance_column to use another column for that information." + end end end else |