Channel

The next model is Channel, which represents a record in the channels table:

#[derive(Debug, Identifiable, Queryable, Associations, Serialize, Deserialize)]
#[belongs_to(User)]
#[table_name = "channels"]
pub struct Channel {
pub id: Id,
pub user_id: Id,
pub title: String,
pub is_public: bool,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
}

This model binds to a table using the table_name attribute and contains all the fields that map to the corresponding columns of the table. To represent the TIMESTAMP SQL type, we use NaiveDateTime from the chrono crate.

The model has a user_id field that maps to a record in the users table. To indicate whether a User model belongs to the users table, we added the belongs_to attribute to this model. The model also has to implement the Associations trait. If the model does that, you can use the belonging_to method of a model to get records belonging to other records with a parental relation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.101.81