Skip to content

Instantly share code, notes, and snippets.

@MittalPatel-BTC
Created May 6, 2019 10:58
Show Gist options
  • Save MittalPatel-BTC/4d0df2bf9e5429a43c4d6cdbfe2bb8bf to your computer and use it in GitHub Desktop.
Save MittalPatel-BTC/4d0df2bf9e5429a43c4d6cdbfe2bb8bf to your computer and use it in GitHub Desktop.
Rails 5 touch method
# Rails 5.2
> User.count
SELECT COUNT(\*) FROM "users"
=> 3
> User.all.touch_all
=> Traceback (most recent call last):1: from (irb):2
NoMethodError (undefined method 'touch_all' for #<User::ActiveRecord_Relation:0x00007fe6261f9c58>)
> User.all.each(&:touch)
SELECT "users".* FROM "users"
begin transaction
UPDATE "users" SET "updated_at" = ? WHERE "users"."id" = ? [["updated_at", "2019-04-20 16:23:31.388028"], ["id", 1]]
commit transaction
begin transaction
UPDATE "users" SET "updated_at" = ? WHERE "users"."id" = ? [["updated_at", "2019-04-20 16:23:31.418028"], ["id", 2]]
commit transaction
begin transaction
UPDATE "users" SET "updated_at" = ? WHERE "users"."id" = ? [["updated_at", "2019-04-20 16:23:31.518028"], ["id", 3]]
commit transaction
=> [#<User id: 1, name: "John", email: "[email protected]", rating: 2, created_at: "2019-04-10 16:09:29", updated_at: "2019-04-20 16:23:31">, #<User id: 2, name: "Marry", email: "[email protected]", rating: 4, created_at: "2019-04-10 16:09:43", updated_at: "2019-04-20 16:23:31">, #<User id: 3, name: "Poll", email: "[email protected]", rating: 4, created_at: "2019-04-10 16:09:45", updated_at: "2019-04-20 16:23:31">]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment