DEV Community

Sushant Bajracharya
Sushant Bajracharya

Posted on • Updated on

Ecto's Repo.insert

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

Top comments (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

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