pub struct GenericForeignKey {
pub content_type_id: i64,
pub object_pk: i64,
}Expand description
“Generic foreign key” pair — a runtime pointer at any registered
model’s row, formed by (content_type_id, object_pk). Sub-slice
F.3 of the v0.15.0 ContentType plan.
Models embed it as two plain columns plus this struct used at
the API surface — there’s no dedicated SQL type for “generic
FK”, just the convention that content_type_id references
rustango_content_types.id and object_pk is the target row’s
primary key value. The framework hydrates targets via
prefetch_generic.
§Why not a typed T: Model field?
The whole point of the generic shape is that the target type
isn’t known at compile time — a single audit log row, comment,
activity-stream entry, or tag can point at any model. Typed FKs
(ForeignKey<User>) are the right choice when the target type
is fixed; GenericForeignKey is for the “could be anything”
case Django’s contenttypes framework solves.
Fields§
§content_type_id: i64FK to rustango_content_types.id. Identifies which model
the object_pk lives in.
object_pk: i64Primary key of the target row in the table named by the
matching ContentType. Always i64 — the framework’s
Auto<T> PK is i64 and non-Auto PKs that ride this path
must be i64-coercible.
Implementations§
Source§impl GenericForeignKey
impl GenericForeignKey
Sourcepub const fn new(content_type_id: i64, object_pk: i64) -> Self
pub const fn new(content_type_id: i64, object_pk: i64) -> Self
Construct a GFK from a ContentType row + a target PK. The natural shape when the caller already has the ContentType in hand (audit log writer, comment-create handler, etc.).
Trait Implementations§
Source§impl Clone for GenericForeignKey
impl Clone for GenericForeignKey
Source§fn clone(&self) -> GenericForeignKey
fn clone(&self) -> GenericForeignKey
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GenericForeignKey
impl Debug for GenericForeignKey
Source§impl PartialEq for GenericForeignKey
impl PartialEq for GenericForeignKey
Source§fn eq(&self, other: &GenericForeignKey) -> bool
fn eq(&self, other: &GenericForeignKey) -> bool
self and other values to be equal, and is used by ==.impl Copy for GenericForeignKey
impl Eq for GenericForeignKey
impl StructuralPartialEq for GenericForeignKey
Auto Trait Implementations§
impl Freeze for GenericForeignKey
impl RefUnwindSafe for GenericForeignKey
impl Send for GenericForeignKey
impl Sync for GenericForeignKey
impl Unpin for GenericForeignKey
impl UnsafeUnpin for GenericForeignKey
impl UnwindSafe for GenericForeignKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more