Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Modifying the schemas

Now that we've gone back and added user_id to the actual database table, we'll need to mirror those changes in our codebase as well. So, let's open up the schema file for the polls table first. In here, inside the schema block, we need to add a reference to the user in the form of a belongs_to relationship. We'll also need to add an import statement for the Vocial.Accounts.User module, since that lives in a different context and code file as well. Open up lib/vocial/votes/poll.ex to change the schema definition as follows:

defmodule Vocial.Votes.Poll do  # ...  alias Vocial.Accounts.User  schema "polls" do    field :title, :string    has_many :options, Option    belongs_to :user, User    timestamps()  end   # ...end

As a quick sanity ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content