diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-10-05 01:09:43 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-10-05 01:11:40 +0100 |
commit | ee2be435b1e5c0e94a4ee93a1a310e0471a77d07 (patch) | |
tree | d30036d8c7f8520df4c6cd4c47e0f7733abe3525 /activerecord/lib/active_record/errors.rb | |
parent | 5711a35ad8faa3fb6d138b234cbe9acfad27a9a8 (diff) | |
download | rails-ee2be435b1e5c0e94a4ee93a1a310e0471a77d07.tar.gz rails-ee2be435b1e5c0e94a4ee93a1a310e0471a77d07.tar.bz2 rails-ee2be435b1e5c0e94a4ee93a1a310e0471a77d07.zip |
Raise error on unknown primary key.
If we don't have a primary key when we ask for it, it's better to fail
fast. Fixes GH #2307.
Diffstat (limited to 'activerecord/lib/active_record/errors.rb')
-rw-r--r-- | activerecord/lib/active_record/errors.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index ad7d8cd63c..8262b60f6e 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -169,4 +169,18 @@ module ActiveRecord @errors = errors end end + + # Raised when a model attempts to fetch its primary key from the database, but the table + # has no primary key declared. + 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 |