Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-01-15 12:17:34 +01:00
parent 8b4d1ab4e4
commit 32bd50d161
2 changed files with 12 additions and 1 deletions

View file

@ -50,7 +50,7 @@ defmodule Eventos.Events.Event do
field :large_image, :string
field :publish_at, Timex.Ecto.DateTimeWithTimezone
belongs_to :organizer, Account, [foreign_key: :organizer_id]
has_many :tags, Tag
many_to_many :tags, Tag, join_through: "events_tags"
belongs_to :category, Category
many_to_many :participants, Account, join_through: Participant
has_many :event_request, Request
@ -64,6 +64,7 @@ defmodule Eventos.Events.Event do
def changeset(%Event{} = event, attrs) do
event
|> cast(attrs, [:title, :description, :begins_on, :ends_on, :organizer_id, :category_id, :state, :geom, :status, :public, :thumbnail, :large_image, :publish_at])
|> cast_assoc(:tags)
|> validate_required([:title, :description, :begins_on, :ends_on, :organizer_id, :category_id])
|> TitleSlug.maybe_generate_slug()
|> TitleSlug.unique_constraint()

View file

@ -0,0 +1,10 @@
defmodule Eventos.Repo.Migrations.CreateEventsTags do
use Ecto.Migration
def change do
create table(:events_tags, primary_key: false) do
add :event_id, references(:events)
add :tag_id, references(:tags)
end
end
end