toasty_core/schema/app/relation/
has_many.rs

1use crate::{
2    schema::app::{BelongsTo, FieldId, Model, ModelId, Name, Schema},
3    stmt,
4};
5
6#[derive(Debug, Clone)]
7pub struct HasMany {
8    /// Associated model
9    pub target: ModelId,
10
11    /// The association's expression type. This is the type the field evaluates
12    /// to from a user's point of view.
13    pub expr_ty: stmt::Type,
14
15    /// Singular item name
16    pub singular: Name,
17
18    /// The `BelongsTo` association that pairs with this
19    pub pair: FieldId,
20}
21
22impl HasMany {
23    pub fn target<'a>(&self, schema: &'a Schema) -> &'a Model {
24        schema.model(self.target)
25    }
26
27    pub fn pair<'a>(&self, schema: &'a Schema) -> &'a BelongsTo {
28        schema.field(self.pair).ty.expect_belongs_to()
29    }
30}