aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-09-16 05:02:40 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-09-16 08:57:09 +0900
commitd681adbbb5e945994580a4e3b5103081888491b9 (patch)
treeb41f9a14c5d3a40c31fb5fa45185389af60d397a /activerecord/test/cases/relation
parent68d6c1353acd9235d3f73db04684ea82d26c9a98 (diff)
downloadrails-d681adbbb5e945994580a4e3b5103081888491b9.tar.gz
rails-d681adbbb5e945994580a4e3b5103081888491b9.tar.bz2
rails-d681adbbb5e945994580a4e3b5103081888491b9.zip
Use table name qualified column name for update counters
MySQL supports JOINs to UPDATE, so if column name isn't qualified by table name, it would cause an ambiguous error: ``` Mysql2::Error: Column 'integer' in field list is ambiguous: UPDATE `pets` INNER JOIN `toys` ON `toys`.`pet_id` = `pets`.`pet_id` SET `integer` = COALESCE(`integer`, 0) + 1 WHERE `toys`.`name` = ? ```
Diffstat (limited to 'activerecord/test/cases/relation')
-rw-r--r--activerecord/test/cases/relation/update_all_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation/update_all_test.rb b/activerecord/test/cases/relation/update_all_test.rb
index e199f76197..09c365f31b 100644
--- a/activerecord/test/cases/relation/update_all_test.rb
+++ b/activerecord/test/cases/relation/update_all_test.rb
@@ -94,6 +94,14 @@ class UpdateAllTest < ActiveRecord::TestCase
assert_equal posts(:welcome), comments(:greetings).post
end
+ def test_update_counters_with_joins
+ assert_nil pets(:parrot).integer
+
+ Pet.joins(:toys).where(toys: { name: "Bone" }).update_counters(integer: 1)
+
+ assert_equal 1, pets(:parrot).reload.integer
+ end
+
def test_touch_all_updates_records_timestamps
david = developers(:david)
david_previously_updated_at = david.updated_at