Ecto.Schema のフィールドを定義するときに、struct を参照する virtual
なフィールドを定義したい。
field :my_struct, MyStruct, virtual: true
しかし、こうするとコンパイルエラーになってしまう。
== Compilation error in file ... ==
** (ArgumentError) schema MyStruct is not a valid type for field :my_struct. Did you mean to use belongs_to, has_one, has_many, embeds_one, or embeds_many instead?
かといって、has_one/3
などのリファレンスを読んでも virtual
オプションはない。結局、タイプを :any
とすることで切り抜けたが、型を明示するためにもできれば struct を指定したいところ。
field :my_struct, :any, virtual: true