Trait aragog::Link [−][src]
The Link
trait of the Aragog library.
It allows to define a query relation between different models.
Example
#[derive(Clone, Serialize, Deserialize, Record, Validate)] pub struct Order { pub content: String, pub user_id: String, } #[derive(Clone, Serialize, Deserialize, Record, Validate)] pub struct User {} impl Link<Order> for DatabaseRecord<User> { fn link_query(&self) -> Query { Order::query().filter(Comparison::field("user_id").equals_str(self.key()).into()) } } let user = DatabaseRecord::create(User {}, &database_pool).await.unwrap(); let order = DatabaseRecord::create( Order { content: "content".to_string(), user_id: user.key().clone() }, &database_pool).await.unwrap(); let orders = user.linked_models(&database_pool).await.unwrap(); assert_eq!(user.key(), &orders.first().unwrap().user_id);
Required methods
fn link_query(&self) -> Query
[src]
Defines the query to execute to find the T
models linked to Self
Example
#[derive(Clone, Serialize, Deserialize, Record, Validate)] pub struct Order { pub content: String, pub user_id: String, } #[derive(Clone, Serialize, Deserialize, Record, Validate)] pub struct User {} impl Link<Order> for DatabaseRecord<User> { fn link_query(&self) -> Query { Order::query().filter(Comparison::field("user_id").equals_str(self.key()).into()) } }
Provided methods
#[must_use]fn linked_models<'life0, 'life1, 'async_trait, D>(
&'life0 self,
db_pool: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<RecordQueryResult<T>, ServiceError>> + Send + 'async_trait>> where
Self: Sized,
D: DatabaseAccess,
T: 'async_trait,
D: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
[src]
&'life0 self,
db_pool: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<RecordQueryResult<T>, ServiceError>> + Send + 'async_trait>> where
Self: Sized,
D: DatabaseAccess,
T: 'async_trait,
D: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
Retrieves the records matching the defined link_query
. Type inference may be required.