Derive Macro diesel_derives::Identifiable

source ·
#[derive(Identifiable)]
{
    // Attributes available to this derive:
    #[diesel]
    #[table_name]
    #[column_name]
    #[primary_key]
}
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’s not, 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 very simple pluralization rules. It only adds an s to the end, and converts CamelCase to snake_case. If your table name does not 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 is 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 to snake_case with an added s 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 to to some_column_name. By default the field name is used as column name.