pub trait Model:
Sized
+ Send
+ Sync
+ 'static {
type Pk: DbType + Clone + PartialEq + Debug;
const META: &'static ModelMeta;
// Required methods
fn pk(&self) -> Self::Pk;
fn set_pk(&mut self, value: Value) -> Result<(), QueryError>;
fn is_unsaved(&self) -> bool;
fn to_values(&self) -> Vec<(&'static str, Value)>;
fn from_row(row: &Row, prefix: &str) -> Result<Self, QueryError>;
// Provided method
fn objects(db: &Db) -> QuerySet<Self> { ... }
}Expand description
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn set_pk(&mut self, value: Value) -> Result<(), QueryError>
fn set_pk(&mut self, value: Value) -> Result<(), QueryError>
Store a primary key generated by the database after an insert.
§Errors
QueryError::Decode if value does not fit the pk type.
Sourcefn is_unsaved(&self) -> bool
fn is_unsaved(&self) -> bool
Whether save must INSERT: true for an auto primary key that still
holds its default (e.g. 0). Models with a manual key return false;
save then tries UPDATE and falls back to INSERT.
Sourcefn to_values(&self) -> Vec<(&'static str, Value)>
fn to_values(&self) -> Vec<(&'static str, Value)>
Every column in ModelMeta::fields order, as (column, value).
Sourcefn from_row(row: &Row, prefix: &str) -> Result<Self, QueryError>
fn from_row(row: &Row, prefix: &str) -> Result<Self, QueryError>
Decode a model from row.
Columns are looked up as prefix + column: prefix is "" for the
root model and "author__" for a model loaded via select_related.
§Errors
QueryError::Decode naming the missing or mistyped column.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".