October 2019
Intermediate to advanced
358 pages
8h 22m
English
After the migration, Ecto generated a schema. This file is responsible for identifying the fields in a way that ties in to both the database table and the Elixir struct. Now let’s take a look at the schema in lib/rumbl/multimedia/video.ex:
| | schema "videos" do |
| | field :description, :string |
| | field :title, :string |
| | field :url, :string |
| | field :user_id, :id |
| | |
| | timestamps() |
| | end |
Our schema sets up a user_id field, of type :id, while our migration defines a :user_id foreign key. To relate our data at the schema level, we need to tell Ecto about our Video to User association. Replace your field :user_id, :id line in your video schema with the ...
Read now
Unlock full access