feat(reference): add target extractor and constructor helpers on ForeignRef
This commit is contained in:
parent
404f6820f3
commit
22ab9479b0
1 changed files with 12 additions and 0 deletions
|
|
@ -38,12 +38,24 @@ impl<T: Sized + DatabaseLine> Serialize for ForeignRef<T> {
|
|||
}
|
||||
|
||||
impl<T: Sized + DatabaseLine> ForeignRef<T> {
|
||||
pub fn from_id(entity_id: &str) -> ForeignRef<T> {
|
||||
ForeignRef {
|
||||
target_type: PhantomData,
|
||||
target_id: entity_id.into()
|
||||
}
|
||||
}
|
||||
pub fn new(entity: &T) -> ForeignRef<T> {
|
||||
ForeignRef {
|
||||
target_type: PhantomData,
|
||||
target_id: entity.id(),
|
||||
}
|
||||
}
|
||||
pub fn target_id_str(&self) -> &str {
|
||||
&self.target_id.as_str()
|
||||
}
|
||||
pub fn to_string(&self) -> String {
|
||||
self.target_id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, DB: Database, T: Sized + DatabaseLine> Decode<'r, DB> for ForeignRef<T>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue