pub struct Relation {
pub model: String,
pub field: String,
pub kind: RelationKind,
pub display_field: Option<String>,
pub required: Option<bool>,
pub on_delete: Option<String>,
}Expand description
First-class foreign-key annotation on a field.
Only belongs_to is stored explicitly. The inverse direction
(has_many) is inferred at runtime by
Schema::incoming_relations; adding it as a stored variant
would double-book the same information and drift over time.
Conservative by design: if any of these fields is missing, old
consumers ignore the whole relation key because the parent
field is Option<Relation>.
§0.9.0 write path
The primary writer is the #[rustio(belongs_to = "...")] macro
attribute, which populates AdminRelation on the compiled model.
Schema::from_admin copies that into SchemaField.relation so
rustio.schema.json always matches the compiled types. Hand-edits
to rustio.schema.json still work (the AI layer reads this shape),
but the macro is authoritative: the next rustio schema overwrites
any hand-added block without a matching macro attribute.
Fields§
§model: StringTarget model name (e.g. "Patient").
field: StringTarget field name — conventionally "id", but explicit so a
future release can support multi-column keys without another
schema bump.
kind: RelationKindDirection marker. Stored writes only accept BelongsTo;
HasMany is reserved for inferred inverse results.
display_field: Option<String>0.9.0 — optional name of the target’s column whose value should
be rendered as the human label for this foreign key in the
admin. None means the admin will show #<id> rather than
guess a column. No inference (full_name / name / title
fallback) is ever applied — this is opt-in on purpose so that
operators see raw IDs only when the model author has not
declared a display field.
required: Option<bool>0.9.0 — whether the FK column is NOT NULL. None is treated
the same as Some(false) (nullable) — the Option lets 0.8.x
schema files round-trip byte-identically when they don’t know
about this key.
on_delete: Option<String>0.9.0 — SQL ON DELETE policy. Stored as the serialised form
("restrict" / "cascade" / "set_null") so older tooling
just sees a string. Missing → treat as restrict.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Relation
impl<'de> Deserialize<'de> for Relation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Relation
Auto Trait Implementations§
impl Freeze for Relation
impl RefUnwindSafe for Relation
impl Send for Relation
impl Sync for Relation
impl Unpin for Relation
impl UnsafeUnpin for Relation
impl UnwindSafe for Relation
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<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