To represent records in the memberships model, we added the Membership model:
#[derive(Debug, Identifiable, Queryable, Associations, Serialize, Deserialize)]
#[belongs_to(Channel)]
#[belongs_to(User)]
#[table_name = "memberships"]
pub struct Membership {
pub id: Id,
pub channel_id: Id,
pub user_id: Id,
}
This model has set relations with the Channel and User models. For example, if you want to get all the memberships of a user, you can use the belonging_to method:
let memberships = Membership::belonging_to(&user)
.load::<Membership>(&conn);