elixir - `virtual: true` 对嵌入式架构有影响吗?

标签 elixir ecto

documentation for Ecto.Schema关于 :virtual 选项如下:

:virtual - When true, the field is not persisted to the database.

embedded_schema/1函数表示它描述了一个专门保存在内存中的模式。 (即它永远不会持久化到数据库中。)这是否意味着对于嵌入式模式, :virtual 选项无效?

最佳答案

关于 Ecto.Schema.#embedded_schema/1 的文档实际上说:

An embedded schema is either embedded into another schema or kept exclusively in memory. For this reason, an embedded schema does not require a source name and it does not include a metadata field.

当嵌入到另一个架构中时,它充当直接注入(inject)到目标架构中的代码片段,并且 :virtual 字段照常运行。

当保存在内存中时,:virtual 字段仍然有效

  • 与其他字段不同,通过声明类型 :any 允许选择性跳过类型检查
  • 未在 __schema__(:fields) 中列出
  • 不支持使用__schema__(:type, field)查询类型
  • 不支持 :autogenerate 也不支持 :read_after_writes 选项

关于elixir - `virtual: true` 对嵌入式架构有影响吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63291589/

相关文章:

elixir - 无法识别 2 个字段上的 unique_constraint

testing - 对 Elixir Ecto 验证测试不起作用的原因感到困惑

postgresql - Elixir/Ecto/Postgres 将多列选为一列

elixir - Ecto 模型 `undefined function: ` 使用宏时 *** 在 iex 中***

elixir - 字符串/二进制参数末尾的模式匹配

elixir - Phoenix 附加布局变量,例如 @inner

postgresql - Ecto 中的所有查询

time - Elixir 中的 utc_offset 返回错误的时区偏移量

elixir - 在 Elixir 的 ExUnit 中,是否可以只运行一个测试?

elixir - Elixir 中的 `@type t::%__MODULE__{}` 是什么意思