Rails 记录更新一致性检查

发布于 2024-12-02 13:13:30 字数 664 浏览 0 评论 0原文

我将启动一个系统,我们选择了 Rails,因为它满足了我们所有的需求。

我们需要在系统的某些点上保持数据库更新的一致性,我记得我在一些官方文档中发现rails可以自动检查记录的版本,但是我用谷歌搜索了很多,但我无法再次找到这些页面。

问题如下:

  • 假设数据库的表中存在一条记录。比方说,一个“帐户”。
  • 假设名为 Bob 的用户找到该记录并开始编辑它。假设用户将其名称从“Incomings”更改为“Sales”。
  • 假设在 Bob 编辑记录时,另一个名为 Susan 的用户找到完全相同的记录并开始编辑它。假设 Susan 想要将帐户名称从“收入”更改为“服务费”。
  • 然后,Bob 保存他的更改。
  • 鲍勃保存他的更改后,苏珊尝试保存她的更改。

此时,系统应该通知 Susan,另一个用户已经更改了记录,并且她的更改无法保存。

我可以手动执行此验证,但我记得这可以由 Rails 自动完成。我记得数据库表上需要验证的唯一要求是添加一个“版本”列,Rails 会处理这个问题。我真的不记得该列是否必须称为“版本”或其他名称,但事实是只有列才能启用此功能。

问题是我再也找不到该文档了。如果有人能为我提供该文档的链接,我将不胜感激,因为“版本”列的要求就是我所记得的,我不想知道我还必须处理哪些其他事情。

提前致谢。

I will start a system and we have chosed rails because it covers all our needs.

We need consistency on database updates in some point of the system and I remember that I found in some official documentation that rails can check for the versions of the records automatically, however I have googled a lot and I cannot find those pages again.

The problem is the following:

  • Suppose that there exists a record in a table of the database. Let's say, an "account".
  • Suppose that a user named Bob finds that record and starts editing it. Let's say that the user is changing its name from "Incomings" to "Sales".
  • Suppose that at the time Bob is editing the record, another user named Susan find exactly the same record and starts editing it. Let's say that Susan wants to change the name of the account from "Incomings" to "Service fees".
  • Then, Bob saves his changes.
  • After Bob saves his changes, Susan tries to save her changes.

At this point, the system should inform to Susan that another user has changed the record and her changes cannot be saved.

I can do this validation manually, but I remember that this can be done by Rails automatically. I remember that the only requeriment on the tables of the database where is required this validation is to add a "version" column and Rails will take care of this. Really I don't remember if the column must be called "version" or something else, but the fact is that only a columns enables this feature.

The problem is that I cannot find that documentation anymore. If anyone could provide me the link to that documentation I will be thankful, because the requeriment of the "version" column is all what I remember and I wan't to know what other things I must take care of.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云仙小弟 2024-12-09 13:13:30

好吧,我已经找到了我自己问题的答案。

该文档位于 API 上,可以在此处找到:

http://api.rubyonrails .org/classes/ActiveRecord/Locking/Optimistic.html

该文档非常短!我对所需列的名称是错误的。该列的正确名称是“lock_version”。

至少感谢所有阅读我的问题的人。

Well, I have found the answer to my own question.

The documentation is on the API and can be found here:

http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html

The documentation is very short! And I was wrong on the name of the required column. The correct name of the column is 'lock_version'.

Thank you to all who, at least, read my question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文