DEV Community


Ecto's Repo.insert

Sushant Bajracharya
My key strengths: Discipline and Focus
Updated on ・1 min read

If you have default values set in your database, then Repo.insert will not return its value.

To return the value, you have to pass Repo.insert(returning: true)

If you dont want to do returning: true you can set default return value in your schema.

schema "rooms" do
  field :enable_chat, :boolean, default: false

Then when you do insert, it will return the default false

Discussion (2)

sinni800 profile image

That's a cool tidbit of info.

So, does this also count for auto-increment IDs then?

sushant12 profile image
Sushant Bajracharya Author

By default, primary key typically :id are returned without even using returning: true.