toasty_core/schema/app/
fk.rs

1use super::{Field, FieldId, Schema};
2
3#[derive(Debug, Clone)]
4pub struct ForeignKey {
5    pub fields: Vec<ForeignKeyField>,
6}
7
8#[derive(Debug, Clone)]
9pub struct ForeignKeyField {
10    /// The field on the source model that is acting as the foreign key
11    pub source: FieldId,
12
13    /// The field on the target model that this FK field maps to.
14    pub target: FieldId,
15}
16
17impl ForeignKey {
18    pub(crate) fn is_placeholder(&self) -> bool {
19        self.fields.is_empty()
20    }
21}
22
23impl ForeignKeyField {
24    pub fn source<'a>(&self, schema: &'a Schema) -> &'a Field {
25        schema.field(self.source)
26    }
27
28    pub fn target<'a>(&self, schema: &'a Schema) -> &'a Field {
29        schema.field(self.target)
30    }
31}