Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Created October 21, 2016 19:04
Show Gist options
  • Save bnhansn/305582ca3604fa03c6b6674aed18cde1 to your computer and use it in GitHub Desktop.
Save bnhansn/305582ca3604fa03c6b6674aed18cde1 to your computer and use it in GitHub Desktop.
defmodule Sling.Room do
use Sling.Web, :model
schema "rooms" do
field :name, :string
field :topic, :string
many_to_many :users, Sling.User, join_through: "user_rooms"
timestamps()
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:name, :topic])
|> validate_required([:name])
|> unique_constraint(:name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment