PartialModelTrait

Trait PartialModelTrait 

Source
pub trait PartialModelTrait: FromQueryResult {
    // Required method
    fn select_cols_nested<S: QuerySelect>(
        select: S,
        prefix: Option<&str>,
        alias: Option<&'static str>,
    ) -> S;

    // Provided method
    fn select_cols<S: QuerySelect>(select: S) -> S { ... }
}
Expand description

A trait for a part of Model

Required Methods§

Source

fn select_cols_nested<S: QuerySelect>( select: S, prefix: Option<&str>, alias: Option<&'static str>, ) -> S

Used when nesting these structs into each other.

Example impl

fn select_cols_nested<S: QuerySelect>(mut select: S, prefix: Option<&str>) -> S {
    if let Some(prefix) = prefix {
        for col in <<T::Entity as EntityTrait>::Column as Iterable>::iter() {
            let alias = format!("{prefix}{}", col.as_str());
            select = select.column_as(col, alias);
        }
    } else {
        for col in <<T::Entity as EntityTrait>::Column as Iterable>::iter() {
            select = select.column(col);
        }
    }
    select
}

Provided Methods§

Source

fn select_cols<S: QuerySelect>(select: S) -> S

Select specific columns this [PartialModel] needs

No need to implement this method, please implement select_cols_nested instead.

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.

Implementations on Foreign Types§

Source§

impl<T: PartialModelTrait> PartialModelTrait for Option<T>

Source§

fn select_cols_nested<S: QuerySelect>( select: S, prefix: Option<&str>, alias: Option<&'static str>, ) -> S

Implementors§