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