Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (18 sloc) 563 Bytes
defmodule OkrApp.Analytics.AnalyticsEvent do
use Ecto.Schema
import Ecto.Changeset
alias OkrApp.Users.{User}
schema "analytics_events" do
field(:type, :string, null: false)
field(:metadata, :map, null: false)
belongs_to(:user, User, type: :string)
timestamps()
end
def changeset(params = %{}, user: %{id: user_id}) do
params = Map.put(params, "user_id", user_id)
%__MODULE__{}
|> cast(params, [:type, :metadata, :user_id])
|> validate_required([:type, :user_id])
|> foreign_key_constraint(:user_id)
end
end
You can’t perform that action at this time.