Skip to main content

vantage_vista/
reference.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct Reference {
5    pub name: String,
6    pub target: String,
7    pub kind: ReferenceKind,
8    pub foreign_key: String,
9}
10
11impl Reference {
12    pub fn new(
13        name: impl Into<String>,
14        target: impl Into<String>,
15        kind: ReferenceKind,
16        foreign_key: impl Into<String>,
17    ) -> Self {
18        Self {
19            name: name.into(),
20            target: target.into(),
21            kind,
22            foreign_key: foreign_key.into(),
23        }
24    }
25}
26
27/// Cardinality of a relation. Cross-persistence-ness is no longer
28/// encoded here — it's determined at resolution time by whether the
29/// target Vista lives in the same driver or a different one (the
30/// inventory loader knows). YAML specs that previously used
31/// `kind: has_foreign` migrate to `kind: has_one` or `kind: has_many`.
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
33#[serde(rename_all = "snake_case")]
34pub enum ReferenceKind {
35    #[default]
36    HasOne,
37    HasMany,
38}