Skip to main content

Model

Trait Model 

Source
pub trait Model:
    Sized
    + Send
    + Sync
    + 'static {
    const SCHEMA: &'static ModelSchema;

    // Provided methods
    fn reverse_relations() -> &'static [ReverseRelation] { ... }
    fn generic_reverse_relations() -> &'static [GenericReverseRelation] { ... }
}
Expand description

Trait every #[derive(Model)] struct implements.

Carries the static SCHEMA so the registry and the query layer can reach the model’s metadata without an instance.

Required Associated Constants§

Source

const SCHEMA: &'static ModelSchema

Provided Methods§

Source

fn reverse_relations() -> &'static [ReverseRelation]

Reverse-FK existence relations declared via #[rustango(reverse_has(name, child, child_fk_column))]. The macro overrides this to return the populated slice; models with no reverse-has declarations inherit the empty default.

Used by crate::query::QuerySet::where_has / crate::query::QuerySet::where_doesnt_have to resolve a relation name into the correlated-subquery triple (child_table, child_fk_column, self_pk_column) without needing a concrete self. Issue #830 sub-piece.

Source

fn generic_reverse_relations() -> &'static [GenericReverseRelation]

Reverse generic-FK existence relations declared via #[rustango(generic_has(name, child, ct_column, pk_column))]. The macro overrides this to return the populated slice; models with no generic_has declarations inherit the empty default.

Used by the relation-existence family (crate::query::QuerySet::where_has / crate::query::QuerySet::annotate_count / …) to resolve a content-type-discriminated child relation by name. Issue #830.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§