Struct butane::ForeignKey

source ·
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> ForeignKey<T>where T: DataObject,

source

pub fn from_pk(pk: <T as DataObject>::PKType) -> ForeignKey<T>

source

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

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

source

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

Returns a reference to the primary key of the value.

source

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

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 as DataObject>::PKType>

source§

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

source§

fn clone(&self) -> ForeignKey<T>

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> Debug for ForeignKey<T>where T: DataObject,

source§

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

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

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

source§

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

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

impl<T> Dummy<Faker> for ForeignKey<T>where T: DataObject,

Fake data support is currently limited to empty ForeignKey relationships.

source§

fn dummy_with_rng<R>(_: &Faker, _rng: &mut R) -> ForeignKey<T>where R: Rng + ?Sized,

Generate a dummy value for a given type using a random number generator.
§

fn dummy(config: &T) -> Self

Generate a dummy value for a type. 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> From<&T> for ForeignKey<T>where T: DataObject,

source§

fn from(obj: &T) -> ForeignKey<T>

Converts to this type from the input type.
source§

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

source§

fn from(obj: T) -> ForeignKey<T>

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<ForeignKey<T>, Error>

Used to convert a SqlValRef into another type.
source§

fn from_sql(val: SqlVal) -> Result<Self, Error>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 as DataObject>::PKType: Serialize,

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::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> Eq for ForeignKey<T>where T: DataObject,

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
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<T> Fake for T

§

fn fake<U>(&self) -> Uwhere Self: FakeBase<U>,

§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> Uwhere R: Rng + ?Sized, Self: FakeBase<U>,

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same<T> for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

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