The Ecto.Schema docs list some functions that can be used for reflection, e.g. schema.__schema__(:fields)
.
However, there are some additional clauses in the source code that are not listed in the previously-mentioned docs page, e.g. schema.__schema__(:updatable_fields)
.
Should I assume that any clause not present in the docs is part of the private API, which could change at any time? Or can I use them all freely?
5 Likes
Both!
Naw I’m just kidding, it’s a good question. I always assume if It’s not documented it’s private, but it could be an oversight. It’s too bad there’s no way to do the equivalent of @doc false
for matches.
2 Likes
Just giving this a little bump in the hopes that someone else might see it who can provide some insight.
If this doesn’t work, I might just open a quick issue on GitHub so that this question doesn’t need to come up again in the future.
EDIT: Sorry Brother @sodapopcan , I didn’t mean to reply directly to you.
1 Like
That’s all good! I was also hoping someone would give a decisive answer.
1 Like
OK so the answer is “Yes, any non-listed one is private.”
opened 07:08AM - 24 Jan 25 UTC
closed 08:25AM - 24 Jan 25 UTC
Kind:Bug
### Elixir version
N/A
### Database and Version
N/A
### Ecto Versions
lates… t (3.12.5)
### Database Adapter and Versions (postgrex, myxql, etc)
N/A
### Current behavior
The [Ecto.Schema reflection docs](https://hexdocs.pm/ecto/Ecto.Schema.html#module-reflection) list some, but not all of the available `__schema__/1` clauses. The excluded clauses include `:insertable_fields`, `:updatable_fields`, and a few others.
I am unsure if these clauses are part of the "private" API and should not be used in my codebase, or if their exclusion is unintentional. If all clauses are part of the public API, then they should be added to the documentation.
I would be happy to make a pull request to get the ball rolling on this. (At least, for the clauses whose purpose is clear enough to me...)
Thanks
### Expected behavior
The documentation should either describe all available fields, or should explicitly mention that any non-documented clauses are part of the private Ecto API.
3 Likes
IMO not private as in “impossible to access”, but more like “undocumented and subject to change at any time, use at your own risk”. I realize the updated docs say that but “private” is used in the issue so I felt I had to clarify.
2 Likes
Ah, a subtle but relevant distinction.
Thanks for the clarification, I always get the terms wrong.
1 Like