Trait diesel::associations::Identifiable
[−]
[src]
pub trait Identifiable: HasTable { type Id: Hash + Eq; fn id(self) -> Self::Id; }
Represents a struct which can be identified on a single table in the database. This must be implemented to use associations, and some features of updating. This trait is usually implemented on a reference to a struct, not the struct itself.
Deriving
This trait can be automatically derived using diesel_codegen
by adding
#[derive(Identifiable)]
to your struct. The primary key will be assumed to be a field and
column called id
. If it's not, you can annotate your structure with #[primary_key(your_id)]
or #[primary_key(your_id, second_id)]
. By default the table will be assumed to be the plural
form of the struct name (using very dumb pluralization -- it just adds an s
at the end). If
your table name differs from that convention, or requires complex pluralization, it can be
specified using #[table_name = "some_table_name"]
. The inferred table name is considered
public API and will never change without a major version bump.