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>(
17 select: S,
18 _prefix: Option<&str>,
19 _alias: Option<&str>,
20 ) -> S {
21 Self::select_cols(select)
22 }
23}
24
25impl<T: PartialModelTrait> PartialModelTrait for Option<T> {
26 fn select_cols<S: SelectColumns>(select: S) -> S {
27 Self::select_cols_nested(select, None, None)
28 }
29
30 fn select_cols_nested<S: SelectColumns>(
31 select: S,
32 prefix: Option<&str>,
33 _alias: Option<&str>,
34 ) -> S {
35 T::select_cols_nested(select, prefix, _alias)
36 }
37}