use crate::{
relations::{Relation, RelationAttributes},
walkers::{ModelWalker, RelationFieldWalker, RelationWalker},
};
#[derive(Copy, Clone)]
pub struct TwoWayEmbeddedManyToManyRelationWalker<'db>(pub(super) RelationWalker<'db>);
impl<'db> TwoWayEmbeddedManyToManyRelationWalker<'db> {
fn get(&self) -> &'db Relation {
&self.0.db.relations[self.0.id]
}
pub fn model_a(self) -> ModelWalker<'db> {
self.0.db.walk(self.get().model_a)
}
pub fn model_b(self) -> ModelWalker<'db> {
self.0.db.walk(self.get().model_b)
}
pub fn field_a(self) -> RelationFieldWalker<'db> {
let rel = self.get();
match rel.attributes {
RelationAttributes::TwoWayEmbeddedManyToMany { field_a, field_b: _ } => self.0.walk(field_a),
_ => unreachable!(),
}
}
pub fn field_b(self) -> RelationFieldWalker<'db> {
let rel = self.get();
match rel.attributes {
RelationAttributes::TwoWayEmbeddedManyToMany { field_a: _, field_b } => self.0.walk(field_b),
_ => unreachable!(),
}
}
}