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 ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.