diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-10-05 20:20:04 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-10-05 20:21:21 +0100 |
commit | 2e9e647fee59d975c9564d96c924d29ffe57f2a2 (patch) | |
tree | ed70277b1e139e88a63a05b967f36e9eb433d4b0 /activerecord/lib/active_record/errors.rb | |
parent | 64747654ca661d695622c0ad9e33b8d9e6df8048 (diff) | |
download | rails-2e9e647fee59d975c9564d96c924d29ffe57f2a2.tar.gz rails-2e9e647fee59d975c9564d96c924d29ffe57f2a2.tar.bz2 rails-2e9e647fee59d975c9564d96c924d29ffe57f2a2.zip |
Raise an exception on unknown primary key inside AssociationReflection.
An association between two models cannot be made if a relevant key is
unknown, so fail fast rather than generating invalid SQL. Fixes #3207.
Diffstat (limited to 'activerecord/lib/active_record/errors.rb')
-rw-r--r-- | activerecord/lib/active_record/errors.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index ad7d8cd63c..96870cb338 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -169,4 +169,17 @@ module ActiveRecord @errors = errors end end + + # Raised when a primary key is needed, but there is not one specified in the schema or model. + class UnknownPrimaryKey < ActiveRecordError + attr_reader :model + + def initialize(model) + @model = model + end + + def message + "Unknown primary key for table #{model.table_name} in model #{model}." + end + end end |