use diesel::{ dsl::{auto_type, AsSelect}, pg::Pg, prelude::*, }; use uuid::Uuid; use crate::schema::channel_selections; #[derive(Associations, Clone, Debug, Identifiable, Queryable, Selectable)] #[diesel(belongs_to(crate::channels::Channel))] #[diesel(belongs_to(crate::projects::Project))] #[diesel(primary_key(channel_id, project_id))] #[diesel(check_for_backend(Pg))] pub struct ChannelSelection { pub project_id: Uuid, pub channel_id: Uuid, } impl ChannelSelection { #[auto_type(no_type_alias)] pub fn all() -> _ { let select: AsSelect = Self::as_select(); channel_selections::table.select(select) } #[auto_type(no_type_alias)] pub fn with_channel(channel_id: Uuid) -> _ { channel_selections::channel_id.eq(channel_id) } #[auto_type(no_type_alias)] pub fn with_project(project_id: Uuid) -> _ { channel_selections::project_id.eq(project_id) } }