Derive Macro diesel::prelude::Associations
source · #[derive(Associations)]
{
// Attributes available to this derive:
#[diesel]
#[belongs_to]
#[column_name]
#[table_name]
}
Expand description
Implement required traits for the associations API
This derive implement support for diesel’s associations api. Check the
module level documentation of the diesel::associations module for details.
This derive generates the following impls:
impl BelongsTo<Parent> for YourTypeimpl BelongsTo<&'a Parent> for YourType
Attributes
Required container attributes
#[diesel(belongs_to(User))], to specify a child-to-parent relation ship between the current type and the specified parent type (User). If this attribute is given multiple times, multiple relation ships are generated.#[diesel(belongs_to(User, foreign_key = mykey))]variant allows to specify the name of the foreign key. If the foreign key is not specified explicitly, the remote lower case type name with an appended_idis used as foreign key name. (user_idin this example case)
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_casewith an addedsis used as table name.
Optional field attributes
#[diesel(column_name = some_column_name)], overrides the column the current field maps to tosome_column_name. By default the field name is used as column name.