Skip to main content

toasty_core/stmt/
include.rs

1use super::{Node, Path, Query, Visit, VisitMut};
2
3/// An association preload entry on a `Returning::Model` clause.
4#[derive(Debug, Clone, PartialEq)]
5pub struct Include {
6    /// The relation path to preload.
7    pub path: Path,
8
9    /// Query applied to the related rows, if the include is constrained.
10    pub query: Option<Query>,
11}
12
13impl Include {
14    /// Creates an unfiltered `Include`.
15    pub fn new(path: Path) -> Self {
16        Self { path, query: None }
17    }
18
19    /// Creates an `Include` with a relation query.
20    pub fn with_query(path: Path, query: Query) -> Self {
21        Self {
22            path,
23            query: Some(query),
24        }
25    }
26}
27
28impl From<Path> for Include {
29    fn from(path: Path) -> Self {
30        Self::new(path)
31    }
32}
33
34impl Node for Include {
35    fn visit<V: Visit>(&self, mut visit: V) {
36        visit.visit_include(self);
37    }
38
39    fn visit_mut<V: VisitMut>(&mut self, mut visit: V) {
40        visit.visit_include_mut(self);
41    }
42}