【发布时间】:2016-09-21 15:15:49
【问题描述】:
假设我有一个模型,就像这样:
defmodule User do
use MyApp.Web, :model
schema "users" do
field :email, :string
field :first_name, :string
belongs_to :role, Role
has_many :comments, Comment
end
end
用户结构将由关联和字段表示,如下所示:
model = %User{
__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
comments: #Ecto.Association.NotLoaded,
email: "alex@google.com",
first_name: "alex",
role: #Ecto.Association.NotLoaded
}
我怎样才能得到基于这个结构的只有字段的地图?
【问题讨论】: