use crate::{
schema::app::{Cardinality, Model, ModelId, Name, Schema},
stmt,
};
#[derive(Debug, Clone)]
pub struct Via {
pub target: ModelId,
pub expr_ty: stmt::Type,
pub cardinality: Cardinality,
pub path: stmt::Path,
}
impl Via {
pub fn new(
target: ModelId,
expr_ty: stmt::Type,
cardinality: Cardinality,
path: stmt::Path,
) -> Self {
Self {
target,
expr_ty,
cardinality,
path,
}
}
pub fn is_many(&self) -> bool {
self.cardinality.is_many()
}
pub fn is_one(&self) -> bool {
self.cardinality.is_one()
}
pub fn singular(&self) -> Option<&Name> {
self.cardinality.singular()
}
pub fn target<'a>(&self, schema: &'a Schema) -> &'a Model {
schema.model(self.target)
}
}