This version is in beta. Some features may change before release.

Column names

Get the underlying SQL column name off a typed column token — for call sites that want a raw string, without hand-typing one that can drift from the model.

Every column constant #[derive(Model)] emits (User::USERNAME, post::TITLE, ...) is a typed token — .eq(), .order_by(), and friends build predicates and order expressions from it. Some APIs want a plain &str column name instead, most commonly .select_related("...") and .values(&[...]). Call .name() on the token to get that string, so the name stays sourced from the model instead of a hand-typed literal that can silently drift when a column is renamed.

Code
rust
use umbral::prelude::*;
// `#[derive(Model)]` on your `Post` generates the lowercase `post` column module
// alongside it, so in your own crate you import it as:
use crate::post;
 
// `.name()` returns the same `&'static str` the token wraps.
assert_eq!(post::TITLE.name(), "title");
 
let rows = Post::objects()
.filter(post::ID.eq(1))
.values(&[post::ID.name(), post::TITLE.name()])
.await?;

The token also implements AsRef<str> and Display, so it can be passed anywhere a &str or a formatted name is expected without calling .name() explicitly.

See Column types for the full column-token catalogue and Querying for .values() / .select_related().

ormcolumnsquerying