Ecto: Add Repo.reload and Repo.reload!

Created on 27 Aug 2020  路  8Comments  路  Source: elixir-ecto/ecto

It receives a schema (or a list of schemas) and uses the meta information + primary key to reload the same entry from the database. The non bang variant returns nil (or removes the element from the list), the bang variant raises.

Enhancement Intermediate

Most helpful comment

Yes, let's go with Ecto.Repo.Queryable since it is similar to Repo.get (and will most likely rely on it).

All 8 comments

What's the behaviour or associations? Are they unloaded?

@michalmuskala good call, I would unload them and if you want, you can preload/copy the ones you want afterwards.

If implemented, it'd be nice too if insert and update given option to reload the entity also
e.g
I have table users , having fields : id, name, email, active, that default value for field active is true (on DB side not defined on my schema)
I create a new user with required field only (name and email) , the return of insert/1 would have field active with value nil, instead of true
or
I have model user and change its value, while other update it's active state, if I run update it should represent current value on database

@prihandi we already support that by using the returning option or configuring read_after_writes.

Can I take this one?

Yes please!

@josevalim do you think this belongs to Ecto.Repo.Queryable or Ecto.Repo.Schema? I was thinking it should be on schema because it expects schemas only (and not any queryable), but so does Repo.get/2, which is on Ecto.Repo.Queryable and is very similar to Repo.reload.

Yes, let's go with Ecto.Repo.Queryable since it is similar to Repo.get (and will most likely rely on it).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stavro picture stavro  路  4Comments

jbence picture jbence  路  3Comments

alaadahmed picture alaadahmed  路  4Comments

atsheehan picture atsheehan  路  4Comments

ericmj picture ericmj  路  3Comments