pub async fn get_user_roles(
pool: &Pool<MySql>,
user_id: i64,
) -> Result<Vec<Role>>
Expand description
Retrieves all roles assigned to a specific user.
This function fetches all roles that have been assigned to a given user. It’s useful for displaying user roles or checking role-based access control.
§Arguments
pool
- Database connection pool for executing the queryuser_id
- Unique identifier of the user whose roles to retrieve
§Returns
Ok(Vec<Role>)
- Successfully retrieved list of roles for the userErr(anyhow::Error)
- Failed to fetch user roles
§Query Details
This function performs a JOIN operation between the roles and role_user tables to find all roles associated with the specified user.