保存后再次保存Activerecord模型...为什么?

时间:2018-08-08 17:05:58

标签: ruby-on-rails activerecord

我有问题。 我有一个带有一些相关项目的封面调制解调器。

我添加了一个保存后回调,然后使用pry在控制台中打印模型。

[#<Cover::Item:0x007fe190819920
12:22:32 web.1       |   id: 284,
12:22:32 web.1       |   cover_id: 64,
12:22:32 web.1       |   teaser_id: 214,
12:22:32 web.1       |   position: 2,
12:22:32 web.1       |   created_at: Wed, 08 Aug 2018 16:54:47 CEST +02:00,
12:22:32 web.1       |   updated_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00>,
12:22:32 web.1       |  #<Cover::Item:0x007fe190819740
12:22:32 web.1       |   id: 285,
12:22:32 web.1       |   cover_id: 64,
12:22:32 web.1       |   teaser_id: 210,
12:22:32 web.1       |   position: 3,
12:22:32 web.1       |   created_at: Wed, 08 Aug 2018 16:54:47 CEST +02:00,
12:22:32 web.1       |   updated_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00>,
12:22:32 web.1       |  #<Cover::Item:0x007fe190819560
12:22:32 web.1       |   id: 290,
12:22:32 web.1       |   cover_id: 64,
12:22:32 web.1       |   teaser_id: 54,
12:22:32 web.1       |   position: 4,
12:22:32 web.1       |   created_at: Wed, 08 Aug 2018 17:44:27 CEST +02:00,
12:22:32 web.1       |   updated_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00>,
12:22:32 web.1       |  #<Cover::Item:0x007fe190818548
12:22:32 web.1       |   id: 300,
12:22:32 web.1       |   cover_id: 64,
12:22:32 web.1       |   teaser_id: 207,
12:22:32 web.1       |   position: 1,
12:22:32 web.1       |   created_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00,
12:22:32 web.1       |   updated_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00>]

当我按ctrl + d继续活动记录时,更新时间戳记

12:22:58 web.1       |   SQL (1.7ms)  UPDATE "covers" SET "updated_at" = '2018-08-08 16:21:40.388037' WHERE "covers"."id" = $1  [["id", 64]]
12:22:58 web.1       |   SQL (1.5ms)  UPDATE "teasers" SET "updated_at" = '2018-08-08 16:21:40.391480' WHERE "teasers"."type" IN ('Content::Teaser') AND "teasers"."id" = $1  [["id", 219]]
12:22:58 web.1       |   SQL (1.1ms)  UPDATE "contents" SET "updated_at" = '2018-08-08 16:22:58.387353' WHERE "contents"."type" IN ('Content::News') AND "contents"."id" = $1  [["id", 223]]
12:22:58 web.1       |   SQL (1.2ms)  UPDATE "teasers" SET "updated_at" = '2018-08-08 16:21:40.413622' WHERE "teasers"."type" IN ('Content::Teaser') AND "teasers"."id" = $1  [["id", 214]]
12:22:58 web.1       |   SQL (1.2ms)  UPDATE "contents" SET "updated_at" = '2018-08-08 16:22:58.392526' WHERE "contents"."type" IN ('Content::News') AND "contents"."id" = $1  [["id", 218]]
12:22:58 web.1       |   SQL (1.2ms)  UPDATE "teasers" SET "updated_at" = '2018-08-08 16:21:40.425685' WHERE "teasers"."type" IN ('Content::Teaser') AND "teasers"."id" = $1  [["id", 210]]
12:22:58 web.1       |   SQL (1.5ms)  UPDATE "contents" SET "updated_at" = '2018-08-08 16:22:58.397827' WHERE "contents"."type" IN ('Content::News') AND "contents"."id" = $1  [["id", 214]]
12:22:58 web.1       |   SQL (1.2ms)  UPDATE "teasers" SET "updated_at" = '2018-08-08 16:21:40.437788' WHERE "teasers"."type" IN ('Content::Teaser') AND "teasers"."id" = $1  [["id", 54]]
12:22:58 web.1       |   SQL (1.2ms)  UPDATE "contents" SET "updated_at" = '2018-08-08 16:22:58.404283' WHERE "contents"."type" IN ('Content::News') AND "contents"."id" = $1  [["id", 56]]
12:22:58 web.1       |   SQL (1.1ms)  UPDATE "teasers" SET "updated_at" = '2018-08-08 16:21:40.444118' WHERE "teasers"."type" IN ('Content::Teaser') AND "teasers"."id" = $1  [["id", 207]]
12:22:58 web.1       |   SQL (1.4ms)  UPDATE "contents" SET "updated_at" = '2018-08-08 16:22:58.409152' WHERE "contents"."type" IN ('Content::News') AND "contents"."id" = $1  [["id", 211]]
12:22:58 web.1       |    (2.5ms)  COMMIT 

这是问题所在。我在视图中添加了另一个撬,如果我打印模型,这里是日志。

 [#<Cover::Item:0x007fe1a6f4f828
13:03:37 web.1       |   id: 300,
13:03:37 web.1       |   cover_id: 64,
13:03:37 web.1       |   teaser_id: 207,
13:03:37 web.1       |   position: 1,
13:03:37 web.1       |   created_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00,
13:03:37 web.1       |   updated_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00>,
13:03:37 web.1       |  #<Cover::Item:0x007fe1a6f4f418
13:03:37 web.1       |   id: 284,
13:03:37 web.1       |   cover_id: 64,
13:03:37 web.1       |   teaser_id: 214,
13:03:37 web.1       |   position: 3,
13:03:37 web.1       |   created_at: Wed, 08 Aug 2018 16:54:47 CEST +02:00,
13:03:37 web.1       |   updated_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00>,
13:03:37 web.1       |  #<Cover::Item:0x007fe1a6f4f080
13:03:37 web.1       |   id: 285,
13:03:37 web.1       |   cover_id: 64,
13:03:37 web.1       |   teaser_id: 210,
13:03:37 web.1       |   position: 4,
13:03:37 web.1       |   created_at: Wed, 08 Aug 2018 16:54:47 CEST +02:00,
13:03:37 web.1       |   updated_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00>,
13:03:37 web.1       |  #<Cover::Item:0x007fe1a6f4ebd0
13:03:37 web.1       |   id: 290,
13:03:37 web.1       |   cover_id: 64,
13:03:37 web.1       |   teaser_id: 54,
13:03:37 web.1       |   position: 5,
13:03:37 web.1       |   created_at: Wed, 08 Aug 2018 17:44:27 CEST +02:00,
13:03:37 web.1       |   updated_at: Wed, 08 Aug 2018 18:21:40 CEST +02:00>]

封面模型具有act_as_list宝石,但我不了解保存后正在改变物品位置的原因。我的日志中没有任何位置写查询。

0 个答案:

没有答案
相关问题