Skip to content

Instantly share code, notes, and snippets.

@maxcal
Last active January 4, 2021 20:09
Show Gist options
  • Save maxcal/cbf1dc961f2a22506b011d29a27842cc to your computer and use it in GitHub Desktop.
Save maxcal/cbf1dc961f2a22506b011d29a27842cc to your computer and use it in GitHub Desktop.
irb(main):007:0> cats = Cat.all
irb(main):008:0> cats.reload
Cat Load (0.4ms) SELECT "cats".* FROM "cats"
=> #<ActiveRecord::Relation [#<Cat id: 1, name: "Proffessor Fluff", picture: nil, created_at: "2021-01-04 19:36:21", updated_at: "2021-01-04 19:36:21">, #<Cat id: 2, name: "Cindy Clawford", picture: nil, created_at: "2021-01-04 19:37:00", updated_at: "2021-01-04 19:37:00">, #<Cat id: 3, name: "Meowise", picture: nil, created_at: "2021-01-04 19:37:30", updated_at: "2021-01-04 19:37:30">]>
irb(main):009:0> Cat.last.update(name: 'Mr Meowise')
Cat Load (0.4ms) SELECT "cats".* FROM "cats" ORDER BY "cats"."id" DESC LIMIT ? [["LIMIT", 1]]
(0.1ms) begin transaction
Cat Update (5.1ms) UPDATE "cats" SET "name" = ?, "updated_at" = ? WHERE "cats"."id" = ? [["name", "Mr Meowise"], ["updated_at", "2021-01-04 19:38:34.919564"], ["id", 3]]
(5.3ms) commit transaction
=> true
irb(main):010:0> cats.last
=> #<Cat id: 3, name: "Meowise", picture: nil, created_at: "2021-01-04 19:37:30", updated_at: "2021-01-04 19:37:30">
irb(main):011:0> cats.reload
Cat Load (0.2ms) SELECT "cats".* FROM "cats"
=> #<ActiveRecord::Relation [#<Cat id: 1, name: "Proffessor Fluff", picture: nil, created_at: "2021-01-04 19:36:21", updated_at: "2021-01-04 19:36:21">, #<Cat id: 2, name: "Cindy Clawford", picture: nil, created_at: "2021-01-04 19:37:00", updated_at: "2021-01-04 19:37:00">, #<Cat id: 3, name: "Mr Meowise", picture: nil, created_at: "2021-01-04 19:37:30", updated_at: "2021-01-04 19:38:34">]>
irb(main):012:0> cats.last
=> #<Cat id: 3, name: "Mr Meowise", picture: nil, created_at: "2021-01-04 19:37:30", updated_at: "2021-01-04 19:38:34">
irb(main):013:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment