Trait aragog::ForeignLink [−][src]
The ForeignLink
trait of the Aragog library.
It allows to define foreign_key relations 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 ForeignLink<User> for Order { fn foreign_key(&self) -> &str { self.user_id.borrow() } } let user = DatabaseRecord::create(User {}, &database_pool).await.unwrap(); let order = Order { content: "content".to_string(), user_id: user.key().clone() }; let linked_user = order.linked_model(&database_pool).await.unwrap(); assert_eq!(user.id(), linked_user.id());
Required methods
fn foreign_key(&self) -> &str
[src]
Defines the foreign key field to the linked T
model.
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 ForeignLink<User> for Order { fn foreign_key(&self) -> &str { self.user_id.borrow() } }
Provided methods
#[must_use]fn linked_model<'life0, 'life1, 'async_trait, D>(
&'life0 self,
db_pool: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<T>, ServiceError>> + Send + 'async_trait>> where
Self: Sized,
T: 'async_trait,
D: DatabaseAccess,
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<DatabaseRecord<T>, ServiceError>> + Send + 'async_trait>> where
Self: Sized,
T: 'async_trait,
D: DatabaseAccess,
D: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
Retrieves the record matching the defined foreign_key
. Type inference may be required.