Skip to main content

ModelWithPk

Trait ModelWithPk 

Source
pub trait ModelWithPk: Model {
    // Required methods
    fn pk_value(&self) -> FilterValue;
    fn get_column_value(&self, column: &str) -> Option<FilterValue>;
}
Expand description

Runtime access to a model’s primary key and column values.

Used by relation loaders (parent → child FK bucketing) and by upsert to build the conflict-row lookup. Implemented by codegen for every #[derive(Model)] struct and every prax_schema!-generated model.

Both methods return a crate::filter::FilterValue that mirrors exactly what the matching From<T> impl on the binding side would produce, so a PK value extracted here is a drop-in replacement for the same value produced by an equivalent type-checked filter.

Required Methods§

Source

fn pk_value(&self) -> FilterValue

Primary-key value for this row.

Single-column PKs return the appropriate scalar variant. Composite PKs collapse to crate::filter::FilterValue::List in the same declaration order as Model::PRIMARY_KEY.

Source

fn get_column_value(&self, column: &str) -> Option<FilterValue>

Look up a column by its SQL name.

Returns None for column names not present in Model::COLUMNS. The relation executor uses this to extract foreign-key values from a fetched parent row without knowing the concrete FK type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§