August 2024
Intermediate to advanced
374 pages
8h 44m
English
With your model up and running, it’s time to seed your database with the library’s books. Before that happens, you need to make some slight modifications to the generated book resource code.
First, modify BookSearch.Book.changeset/2 to match the following:
| | @doc false |
| | def changeset(book, attrs) do |
| | book |
| | |> cast(attrs, [:author, :title, :description, :embedding]) |
| | |> validate_required([:author, :title, :description]) |
| | end |
Notice that you removed :embedding as a required argument in attrs. Because you compute the embedding from book attributes, you don’t want to have to pass it up front.
Next, add the following put_embedding/1 function to BookSearch.Book:
| | @doc false |
| | def put_embedding(%{changes: ... |
Read now
Unlock full access