toasty_core/schema/app/relation/
has_one.rs1use crate::{
2 schema::app::{BelongsTo, FieldId, FieldTy, Model, ModelId, Schema},
3 stmt,
4};
5
6#[derive(Debug, Clone)]
7pub struct HasOne {
8 pub target: ModelId,
10
11 pub expr_ty: stmt::Type,
14
15 pub pair: FieldId,
17}
18
19impl HasOne {
20 pub fn target<'a>(&self, schema: &'a Schema) -> &'a Model {
21 schema.model(self.target)
22 }
23
24 pub fn pair<'a>(&self, schema: &'a Schema) -> &'a BelongsTo {
25 schema.field(self.pair).ty.expect_belongs_to()
26 }
27}
28
29impl From<HasOne> for FieldTy {
30 fn from(value: HasOne) -> Self {
31 Self::HasOne(value)
32 }
33}