DEV Community

Sushant Bajracharya
Sushant Bajracharya

Posted on • Edited on

3 2

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
end

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

Top comments (2)

Collapse
 
sinni800 profile image
sinni800

That's a cool tidbit of info.

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

Collapse
 
sushant12 profile image
Sushant Bajracharya

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay