File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
lib/active_record/relation Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ def take!
141
141
#
142
142
# Product.where(["price = %?", price]).sole
143
143
def sole
144
- found , undesired = limit ( 2 )
144
+ found , undesired = take ( 2 )
145
145
146
146
if found . nil?
147
147
raise_record_not_found_exception!
Original file line number Diff line number Diff line change @@ -794,6 +794,15 @@ def test_sole_failing_many
794
794
end
795
795
end
796
796
797
+ def test_sole_on_loaded_relation
798
+ relation = Topic . where ( "title = 'The First Topic'" ) . load
799
+ expected_topic = topics ( :first )
800
+
801
+ assert_no_queries do
802
+ assert_equal expected_topic , relation . sole
803
+ end
804
+ end
805
+
797
806
def test_first
798
807
assert_equal topics ( :second ) . title , Topic . where ( "title = 'The Second Topic of the day'" ) . first . title
799
808
end
You can’t perform that action at this time.
0 commit comments