#[derive(Identifiable)]
{
// Attributes available to this derive:
#[diesel]
}
Expand description
Implements Identifiable
for references of the current type
By default, the primary key field is assumed to be a single field called id
.
If it isn’t, you can put #[diesel(primary_key(your_id))]
on your struct.
If you have a composite primary key, the syntax is #[diesel(primary_key(id1, id2))]
.
By default, #[derive(Identifiable)]
will assume that your table is
in scope and its name is the plural form of your struct name.
Diesel uses basic pluralization rules.
It only adds an s
to the end, and converts CamelCase
to snake_case
.
If your table name doesn’t follow this convention or is not in scope,
you can specify a path to the table with #[diesel(table_name = path::to::table)]
.
Our rules for inferring table names are considered public API.
It will never change without a major version bump.
This derive generates the following impls:
impl Identifiable for &'a YourType
impl Identifiable for &'_ &'a YourType
§Attributes
§Optional container attributes
#[diesel(table_name = path::to::table)]
specifies a path to the table this type belongs to. The path is relative to the current module. If this attribute is not used, the type name converted tosnake_case
with an addeds
is used as table name#[diesel(primary_key(id1, id2))]
to specify the struct field that that corresponds to the primary key. If not used,id
will be assumed as primary key field
§Optional field attributes
#[diesel(column_name = some_column_name)]
, overrides the column the current field maps tosome_column_name
. By default, the field name is used as a column name.