pub trait Identifiable: HasTable {
    type Id: Hash + Eq;

    fn id(self) -> Self::Id;
}
Expand description

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 (update(&your_struct) is equivalent to update(YourStruct::table().find(&your_struct.primary_key())).

This trait is usually implemented on a reference to a struct, not on the struct itself. It can be derived.

Required Associated Types§

The type of this struct’s identifier.

For single-field primary keys, this is typically &'a i32, or &'a String For composite primary keys, this is typically (&'a i32, &'a i32) or (&'a String, &'a String), etc.

Required Methods§

Returns the identifier for this record.

This takes 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 Id.

Implementors§