Diesel "get_result" return invalid values to invalid variable

Hi !

For a few days, I have been facing a problem that I cannot resolve and I cannot find this problem on the Internet or github issues.

Quickly, with diesel, when I fetch the result of a query, the retrieved data does not go into their respective variables.

For example, with the struct :

#[derive(Debug, Deserialize, Serialize, Queryable, Insertable)]
#[table_name = "user"]
pub struct User {
    pub id: i32,
    pub unique_id: String,
    pub firstname: String,
    pub lastname: String,
    pub email: String,
    pub password: String,
    pub jam_id: Option<String>,
    pub profile_icon: String,

and the table schema :

table! {
    user (id) {
        id -> Int4,
        firstname -> Text,
        lastname -> Text,
        email -> Text,
        password -> Text,
        unique_id -> Text,
        jam_id -> Nullable<Text>,
        profile_icon -> Text,

When I get, for example, all users with this :

pub fn find_users(conn: &PgConnection) -> QueryResult<Vec<User>> {

I've got data like this : (in this form -> struct variable = result from diesel query)

User.email = password
User.firstname = lastname
User.unique_id = firstname

and so on...

Basically, the recovered data does not go into the right variables . I don't know why I have this behavior. However, I know that the data that I record is correctly placed in the database and in their respective good columns.

Any Idea ?

Thank you !

They have to be in the same order in the schema and struct.

Thank you very much ! It works now !

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.