Skip to content

Renaming struct params for db use #484

@xelab04

Description

@xelab04

This is possibly a bit of a complex issue. I have a model I defined here:

#[model]
pub struct Meetup {
    #[model(primary_key)]
    pub id: Auto<i32>,
    pub r#type: LimitedString<255>,
    pub title: LimitedString<255>,
    pub r#abstract: String,
}

For a field like title, I have no issues. But for field names such as type or abstract, which are reserved keywords, I need to add the r# prefix.
And when the migration is created, it takes literally r#type. Also, there are times where you can have a parameter of a certain name but want to map it to a different name in the db.

Maybe having something like the following would be useful?

#[model]
pub struct Meetup {
    #[model(primary_key)]
    pub id: Auto<i32>,
    #[dbfield("type")]
    pub r#type: LimitedString<255>,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions