pub struct ForeignKey<T>where
    T: DataObject,{ /* private fields */ }
Expand description

Used to implement a relationship between models.

Initialize using From or from_pk

Examples

#[model]
struct Blog {
  ...
}
#[model]
struct Post {
  blog: ForeignKey<Blog>,
  ...
}

Implementations§

source§

impl<T: DataObject> ForeignKey<T>

source

pub fn from_pk(pk: T::PKType) -> Self

source

pub fn get(&self) -> Result<&T>

Returns a reference to the value. It must have already been loaded. If not, returns Error::ValueNotLoaded

source

pub fn pk(&self) -> T::PKType

Returns a reference to the primary key of the value.

source

pub fn load(&self, conn: &impl ConnectionMethods) -> Result<&T>

Loads the value referred to by this foreign key from the database if necessary and returns a reference to it.

Trait Implementations§

source§

impl<T> AsPrimaryKey<T> for ForeignKey<T>where T: DataObject,

source§

fn as_pk(&self) -> Cow<'_, T::PKType>

source§

impl<T: DataObject> Clone for ForeignKey<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: DataObject> Debug for ForeignKey<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, T> Deserialize<'de> for ForeignKey<T>where T: DataObject, T::PKType: Deserialize<'de>,

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> FieldType for ForeignKey<T>where T: DataObject,

source§

const SQLTYPE: SqlType = <<T as DataObject>::PKType>::SQLTYPE

§

type RefType = <<T as DataObject>::PKType as FieldType>::RefType

Reference type. Used for ergonomics with String (which has reference type str). For most, it is Self
source§

impl<T: DataObject> From<&T> for ForeignKey<T>

source§

fn from(obj: &T) -> Self

Converts to this type from the input type.
source§

impl<T: DataObject> From<T> for ForeignKey<T>

source§

fn from(obj: T) -> Self

Converts to this type from the input type.
source§

impl<T> FromSql for ForeignKey<T>where T: DataObject,

source§

fn from_sql_ref(valref: SqlValRef<'_>) -> Result<Self>

Used to convert a SqlValRef into another type.
source§

fn from_sql(val: SqlVal) -> Result<Self>where Self: Sized,

Used to convert a SqlVal into another type. The default implementation calls Self::from_sql_ref(val.as_ref()), which may be inefficient. This method is chiefly used only for primary keys: a more efficient implementation is unlikely to provide benefits for types not used as primary keys.
source§

impl<T, U> PartialEq<U> for ForeignKey<T>where U: AsPrimaryKey<T>, T: DataObject,

source§

fn eq(&self, other: &U) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for ForeignKey<T>where T: DataObject, T::PKType: Serialize,

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T> ToSql for ForeignKey<T>where T: DataObject,

source§

fn to_sql(&self) -> SqlVal

source§

fn to_sql_ref(&self) -> SqlValRef<'_>

source§

fn into_sql(self) -> SqlVal

The default implementation simply calls to_sql. Provide an alternative implementation if greater efficiency can be realized by consuming self.
source§

impl<T: DataObject> Eq for ForeignKey<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for ForeignKey<T>where T: UnwindSafe + RefUnwindSafe,

§

impl<T> Send for ForeignKey<T>where T: Send,

§

impl<T> !Sync for ForeignKey<T>

§

impl<T> Unpin for ForeignKey<T>

§

impl<T> UnwindSafe for ForeignKey<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,