pub fn read_one_join_on_url(
        id: String,
        db: &MysqlConnection,
    ) -> Result<(Self, FieldsDTO), diesel::result::Error> {
        use crate::schema::pages::dsl::page_url;

        let filtered_page = pages::table.filter(page_url.eq(id)).first::<Page>(db)?;

        let modules = Module::belonging_to(&filtered_page).load::<Module>(db)?;

        let categories: Vec<ModuleCategory> = Module::belonging_to(&filtered_page)
            .inner_join(module_category::table)
            .select(module_category::all_columns)
            .load::<ModuleCategory>(db)?;

        let module_array: Vec<(Vec<Module>, ModuleCategory)> = Module::belonging_to(&categories)
            .load::<Module>(db)?
            .grouped_by(&categories)
            .into_iter()
            .zip(categories)
            .collect::<Vec<_>>();

        let category_dtos: Vec<CategoryDTO> = module_array
            .iter()
            .map(|a| CategoryDTO {
                uuid: a.1.uuid.clone(),
                title: a.1.title.clone(),
                modules: a.0.clone().into_iter().map(|m| m.into()).collect(),
            })
            .collect::<Vec<_>>();

        let module_dto = FieldsDTO {
            modules: modules.into_iter().map(|m| m.into()).collect(),
            categories: Some(category_dtos),
        };

        Ok((filtered_page, module_dto))
    }
/// This is used for displaying a page, rather than getting a page's modules/array modules.
This is used for displaying a page, rather than getting a page's modules/array modules.
This is used for displaying a page rather than getting a page ' s modules / array modules .
pub fn read_one_join_on_url(
        id: String,
        db: &MysqlConnection,
    ) -> Result<(Self, FieldsDTO), diesel::result::Error> {
        use crate::schema::pages::dsl::page_url;
        let filtered_page = pages::table.filter(page_url.eq(id)).first::<Page>(db)?;
        let modules = Module::belonging_to(&filtered_page).load::<Module>(db)?;
        let categories: Vec<ModuleCategory> = Module::belonging_to(&filtered_page)
            .inner_join(module_category::table)
            .select(module_category::all_columns)
            .load::<ModuleCategory>(db)?;
        let module_array: Vec<(Vec<Module>, ModuleCategory)> = Module::belonging_to(&categories)
            .load::<Module>(db)?
            .grouped_by(&categories)
            .into_iter()
            .zip(categories)
            .collect::<Vec<_>>();
        let category_dtos: Vec<CategoryDTO> = module_array
            .iter()
            .map(|a| CategoryDTO {
                uuid: a.1.uuid.clone(),
                title: a.1.title.clone(),
                modules: a.0.clone().into_iter().map(|m| m.into()).collect(),
            })
            .collect::<Vec<_>>();
        let module_dto = FieldsDTO {
            modules: modules.into_iter().map(|m| m.into()).collect(),
            categories: Some(category_dtos),
        };
        Ok((filtered_page, module_dto))
    }
pub fn read_one_join_on_url ( id : String , db : & MysqlConnection , ) -> Result < ( Self , FieldsDTO ) , diesel :: result :: Error > { use crate :: schema :: pages :: dsl :: page_url ; let filtered_page = pages :: table . filter ( page_url . eq ( id ) ) . first :: < Page > ( db ) ? ; let modules = Module :: belonging_to ( & filtered_page ) . load :: < Module > ( db ) ? ; let categories : Vec < ModuleCategory > = Module :: belonging_to ( & filtered_page ) . inner_join ( module_category :: table ) . select ( module_category :: all_columns ) . load :: < ModuleCategory > ( db ) ? ; let module_array : Vec < ( Vec < Module > , ModuleCategory ) > = Module :: belonging_to ( & categories ) . load :: < Module > ( db ) ? . grouped_by ( & categories ) . into_iter ( ) . zip ( categories ) . collect :: < Vec < _ > > ( ) ; let category_dtos : Vec < CategoryDTO > = module_array . iter ( ) . map ( | a | CategoryDTO { uuid : a . 1 . uuid . clone ( ) , title : a . 1 . title . clone ( ) , modules : a . 0 . clone ( ) . into_iter ( ) . map ( | m | m . into ( ) ) . collect ( ) , } ) . collect :: < Vec < _ > > ( ) ; let module_dto = FieldsDTO { modules : modules . into_iter ( ) . map ( | m | m . into ( ) ) . collect ( ) , categories : Some ( category_dtos ) , } ; Ok ( ( filtered_page , module_dto ) ) }
This is used for displaying a page, rather than getting a page's modules/array modules.
This is used for displaying a page rather than getting a page ' s modules / array modules .
id
String
db
&MysqlConnection
id
String
db
&MysqlConnection