提交 e2419a45 编写于 作者: S Shimpei Makimoto

Raise an exception when model without primary key calls .find_with_ids

上级 6205476a
* Raise an exception when model without primary key calls `.find_with_ids`.
*Shimpei Makimoto*
* Make `Relation#empty?` use `exists?` instead of `count`.
*Szymon Nowak*
......
......@@ -297,6 +297,8 @@ def using_limitable_reflections?(reflections)
protected
def find_with_ids(*ids)
raise UnknownPrimaryKey.new(@klass) if primary_key.nil?
expects_array = ids.first.kind_of?(Array)
return ids.first if expects_array && ids.first.empty?
......
......@@ -11,6 +11,7 @@
require 'models/developer'
require 'models/customer'
require 'models/toy'
require 'models/matey'
class FinderTest < ActiveRecord::TestCase
fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers, :categories, :categorizations
......@@ -860,6 +861,12 @@ def test_find_one_message_with_custom_primary_key
Toy.reset_primary_key
end
def test_find_without_primary_key
assert_raises(ActiveRecord::UnknownPrimaryKey) do
Matey.find(1)
end
end
def test_finder_with_offset_string
assert_nothing_raised(ActiveRecord::StatementInvalid) { Topic.all.merge!(:offset => "3").to_a }
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册