简而言之,Ecto 如何知道一个结构是 "Stale"
Put simply, how does Ecto know that a struct is "Stale"
在 Changeset documentation 中,它说:
When a conflict happens (a record which has been previously fetched is being updated, but that same record has been modified since it was fetched), an Ecto.StaleEntryError exception is raised.
在 Whosebug、GitHub 和其他地方有很多关于如何修复涉及 StaleEntryError
的各种场景的对话。但是没有解释如何 Ecto 知道一个结构是陈旧的。
底层机制是什么?
您链接到的 Ecto.Changeset
documentation 非常不言自明:
Optimistic locking works by keeping a “version” counter for each record; this counter gets incremented each time a modification is made to a record. Hence, in order to use optimistic locking, a field must exist in your schema for versioning purpose. Such field is usually an integer but other types are supported.
在 Changeset documentation 中,它说:
When a conflict happens (a record which has been previously fetched is being updated, but that same record has been modified since it was fetched), an Ecto.StaleEntryError exception is raised.
在 Whosebug、GitHub 和其他地方有很多关于如何修复涉及 StaleEntryError
的各种场景的对话。但是没有解释如何 Ecto 知道一个结构是陈旧的。
底层机制是什么?
您链接到的 Ecto.Changeset
documentation 非常不言自明:
Optimistic locking works by keeping a “version” counter for each record; this counter gets incremented each time a modification is made to a record. Hence, in order to use optimistic locking, a field must exist in your schema for versioning purpose. Such field is usually an integer but other types are supported.