Skip to main content

Reference

Trait Reference 

Source
pub trait Reference: Send + Sync {
    // Required methods
    fn columns(&self, source_id: &str, target_id: &str) -> (String, String);
    fn build_target(&self, data_source: &dyn Any) -> Box<dyn Any>;
    fn cardinality(&self) -> ReferenceKind;
    fn resolve_from_row(
        &self,
        data_source: &dyn Any,
        source_id_field: &str,
        source_row: &dyn Any,
    ) -> Result<Box<dyn Any>>;
    fn resolve_as_any(&self, source_table: &dyn Any) -> Result<AnyTable>;
    fn target_type_name(&self) -> &'static str;
}
Expand description

Describes a relationship between two tables.

Required Methods§

Source

fn columns(&self, source_id: &str, target_id: &str) -> (String, String)

Given source and target id field names, return (source_column, target_column).

Source

fn build_target(&self, data_source: &dyn Any) -> Box<dyn Any>

Produce a fresh target table (no conditions applied).

Source

fn cardinality(&self) -> ReferenceKind

Cardinality of this relation. HasOne if traversing yields at most one record (the FK lives on the source); HasMany if it can yield any number (the FK lives on the target). Surfaced by Vista::list_references so CLIs / UIs can pick a record-card vs list-grid renderer.

Source

fn resolve_from_row( &self, data_source: &dyn Any, source_id_field: &str, source_row: &dyn Any, ) -> Result<Box<dyn Any>>

Resolve traversal using a known source row. Returns the target table (entity type erased to EmptyEntity) wrapped in Box<dyn Any>, with one eq-condition applied that selects the related rows.

data_source is &T for the source’s TableSource; source_id_field is the name of the source table’s id column (needed by HasMany to pull the join value out of the row); source_row is &Record<T::Value>. HasOne ignores source_id_field and reads its stored foreign_key instead.

Callers immediately downcast the result to Table<T, EmptyEntity>.

Source

fn resolve_as_any(&self, source_table: &dyn Any) -> Result<AnyTable>

Resolve this reference and return an AnyTable.

Legacy path used by Table::get_ref / get_ref_as / get_subquery_as. Slated for deletion in Stage 9 alongside AnyTable; new callers should use resolve_from_row (typed) or Vista::get_ref (erased) instead.

Source

fn target_type_name(&self) -> &'static str

Type name of the target table (for error messages).

Implementors§

Source§

impl<T: TableSource + 'static, SourceE: Entity<T::Value> + 'static, TargetE: Entity<T::Value> + 'static> Reference for HasMany<T, SourceE, TargetE>
where T::Value: Into<Value> + From<Value>, T::Id: Display + From<String>,

Source§

impl<T: TableSource + 'static, SourceE: Entity<T::Value> + 'static, TargetE: Entity<T::Value> + 'static> Reference for HasOne<T, SourceE, TargetE>
where T::Value: Into<Value> + From<Value>, T::Id: Display + From<String>,