April 2019
Beginner to intermediate
244 pages
6h 34m
English
Once you’ve set up schemas for your tables, inserting new records, even records with nested associations, can be done very concisely.
Recall how we inserted a new artists record using Repo.insert_all:
| | Repo.insert_all("artists", [[name: "John Coltrane"]]) |
| | #=> {1, nil} |
With insert_all, we had to provide the table name, and a list of fields containing the new record’s values. And if we wanted the ID of the new record, we had to ask for it with the returning option (which is only available with Postgres):
| | Repo.insert_all("artists", [[name: "John Coltrane"]], returning: [:id]) |
| | #=> {1, [%{id: 8}]} |
As we saw earlier, with schemas, we can ...
Read now
Unlock full access