Rails 数据库创建复式条目
我正在使用固定装置用一些信息预先填充我的数据库,这样我就可以在测试期间杀死数据库并快速重新创建它。
现在,当我使用 Rails 应用程序在数据库中创建一个新条目时,它会创建具有相同信息的两行,并对其中一行添加时间戳,就像使用固定装置创建的一样。
以下是数据库中的一些行
| task_id | procedure_id | created_at | updated_at |
+---------+--------------+---------------------+---------------------+
| 13 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 23 | 5 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 7 | 6 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 3 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 7 | 5 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 27 | 6 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 21 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 21 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 38 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 38 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 37 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 5 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 37 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 5 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 30 | 5 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 3 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 41 | 2 | 2010-11-01 23:44:15 | 2010-11-01 23:44:15 |
| 41 | 3 | 2010-11-01 23:44:15 | 2010-11-01 23:44:15 |
| 41 | 4 | 2010-11-01 23:44:15 | 2010-11-01 23:44:15 |
| 42 | 1 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 42 | 1 | 2010-11-01 23:45:11 | 2010-11-01 23:45:11 |
| 43 | 1 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 43 | 1 | 2010-11-01 23:51:16 | 2010-11-01 23:51:16 |
正如您所看到的,时间 23:40:32 是赛程更新数据库的时间。
请注意最后两组条目,其中 task_id 为 42 和 43,它已为 procedure_id 1 添加了两次,一次显然是在初始设置期间,一次是在我实际执行操作时。
这些任务不在固定装置中,直到初始加载后我才将它们添加到数据库中。
I am using fixtures to pre-populate my database with some information, so I can kill the database and remake it quickly during testing.
Now when I create a new entry in the database using my rails application it is creating two rows with the same information and timestamping one of them as if it were created with the fixture.
here are some lines from the database
| task_id | procedure_id | created_at | updated_at |
+---------+--------------+---------------------+---------------------+
| 13 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 23 | 5 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 7 | 6 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 3 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 7 | 5 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 27 | 6 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 21 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 21 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 38 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 38 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 37 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 5 | 8 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 37 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 5 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 30 | 5 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 3 | 7 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 41 | 2 | 2010-11-01 23:44:15 | 2010-11-01 23:44:15 |
| 41 | 3 | 2010-11-01 23:44:15 | 2010-11-01 23:44:15 |
| 41 | 4 | 2010-11-01 23:44:15 | 2010-11-01 23:44:15 |
| 42 | 1 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 42 | 1 | 2010-11-01 23:45:11 | 2010-11-01 23:45:11 |
| 43 | 1 | 2010-11-01 23:40:32 | 2010-11-01 23:40:32 |
| 43 | 1 | 2010-11-01 23:51:16 | 2010-11-01 23:51:16 |
As you can see the time 23:40:32 was when the fixtures updated the database.
Note the last two sets of entries where task_id is 42 and 43, it has been added for procedure_id 1 twice, once during the initial set up apparently and once when I actually did it.
These tasks are not in the fixtures, I didn't add them to the database until after the initial load.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是:
同时使用 .new 和 .save 创建两个条目?我以为 .new 没有保存到数据库,但删除 .save 后它工作正常。
should be:
using both .new and .save was creating two entries? I thought .new didn't save to the database, but after removing the .save it worked fine.