This trait indicates that a struct represents a single row in a database table.
This must be implemented to use associations.
Additionally, implementing this trait allows you to pass your struct to
update(&your_struct) is equivalent to
This trait is usually implemented on a reference to a struct, not the struct itself.
This trait can be automatically derived by adding
to your struct.
By default, the "id" field is assumed to be a single field called
If it's not, you can put
#[primary_key(your_id)] on your struct.
If you have a composite primary key, the syntax is
#[derive(Identifiable)] will assume that your table
name is the plural form of your struct name.
Diesel uses very simple pluralization rules.
It only adds an
s to the end, and converts
If your table name does not follow this convention
or the plural form isn't just an
you can specify the table name with
#[table_name = "some_table_name"].
Our rules for inferring table names is considered public API.
It will never change without a major version bump.
The type of this struct's identifier.
For single-field primary keys, this is typically
&'a i32, or
For composite primary keys, this is typically
(&'a i32, &'a i32)
(&'a String, &'a String), etc.
Returns the identifier for this record.
self by value, not reference.
This is because composite primary keys
are typically stored as multiple fields.
We could not return
&(String, String) if each string is a separate field.
Because of Rust's rules about specifying lifetimes,
this means that
Identifiable is usually implemented on references
so that we have a lifetime to use for