use async_trait::async_trait;
use sqlx::Pool;
use sqlx::Postgres;
use crate::error::ModelResult;
use crate::model::Model;
use crate::query::QueryBuilder;
#[derive(Debug, Clone)]
pub struct RelationshipMeta {
pub foreign_key: String,
pub local_key: String,
pub related_table: String,
}
#[async_trait]
pub trait Relationship<Parent, Related>
where
Parent: Model + Send + Sync,
Related: Model + Send + Sync,
{
fn meta(&self) -> &RelationshipMeta;
fn parent(&self) -> &Parent;
fn is_loaded(&self) -> bool;
fn set_loaded(&mut self, loaded: bool);
fn query(&self) -> QueryBuilder<Related>;
async fn load(&mut self, pool: &Pool<Postgres>) -> ModelResult<()>;
}