Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove r# prefix when deriving FromQueryResult #494

Merged
merged 1 commit into from
Feb 5, 2022
Merged

Remove r# prefix when deriving FromQueryResult #494

merged 1 commit into from
Feb 5, 2022

Conversation

smrtrfszm
Copy link
Contributor

When deriving FromQueryResult on a struct that has a field with a raw identifier, then in the expanded code the r# prefix isn't stripped.
This is inconsistent with the behaviour of the DeriveEntityModel because that macro removes it.

Example:

#[derive(Debug, FromQueryResult)]
pub struct Example {
    pub r#type: i32,
}

Expands to:

#[automatically_derived]
impl sea_orm::FromQueryResult for Example {
    fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result<Self, sea_orm::DbErr> {
        Ok(Self {
            r#type: row.try_get(pre, "r#type")?,
        })
    }
}

But the column name in the try_get should be type without the r# prefix.

@tyt2y3
Copy link
Member

tyt2y3 commented Jan 30, 2022

thanks for the catch! @billy1624 I imagine we can also add some test cases using the MockInterface?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants