sea_orm/entity/
partial_model.rs

1use crate::{FromQueryResult, SelectColumns};
2
3/// A trait for a part of [Model](super::model::ModelTrait)
4pub trait PartialModelTrait: FromQueryResult {
5    /// Select specific columns this [PartialModel] needs
6    ///
7    /// If you are implementing this by hand, please make sure to read the hints in the
8    /// documentation for `select_cols_nested` and ensure to implement both methods.
9    fn select_cols<S: SelectColumns>(select: S) -> S;
10
11    /// Used when nesting these structs into each other.
12    ///
13    /// This will stop being a provided method in a future major release.
14    /// Please implement this method manually when implementing this trait by hand,
15    /// and ensure that your `select_cols` implementation is calling it with `_prefix` as `None`.
16    fn select_cols_nested<S: SelectColumns>(select: S, _prefix: Option<&str>) -> S {
17        Self::select_cols(select)
18    }
19}
20
21impl<T: PartialModelTrait> PartialModelTrait for Option<T> {
22    fn select_cols<S: SelectColumns>(select: S) -> S {
23        Self::select_cols_nested(select, None)
24    }
25
26    fn select_cols_nested<S: SelectColumns>(select: S, prefix: Option<&str>) -> S {
27        T::select_cols_nested(select, prefix)
28    }
29}