Ecto's Repo.insert

sushant12 profile image Sushant Bajracharya 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


markdown guide

That's a cool tidbit of info.

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


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