Skip to content

Conversation

@mcitem
Copy link
Contributor

@mcitem mcitem commented Jan 29, 2026

PR Info

New Features

  • Permit passing custom derives and attributes to Model or ModelEx.

Motivation

This change allows for granular control over the attributes on both Model and ModelEx. For instance, it enables users to customize the generated TypeScript interface names when using ts-rs with ModelEx.

Usage

#[sea_orm::model]
#[derive(TS, ...)]
// Apply attributes specifically to the generated Model struct
#[sea_orm(model_attrs(ts(rename = "Fruit")))]
// Apply attributes specifically to the generated ModelEx struct
#[sea_orm(model_ex_attrs(ts(rename = "FruitEx")))]
struct Model {
    // ...
}

The code above expands to:

// ...
#[derive(TS, ...)]
#[ts(rename = "Fruit")]
struct Model {
    // ...
}

// ...
#[derive(TS, ...)]
#[ts(rename = "FruitEx")]
struct ModelEx {
    // ...
}

@tyt2y3
Copy link
Member

tyt2y3 commented Jan 29, 2026

Thank you, I think the design is nice

Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you. can you add a test case under tests, like https://github.com/SeaQL/sea-orm/blob/master/tests/derive_iden_tests.rs ?

we can call it derive_model_tests. we don't have to use the actual ts-rs crate, may be some built-in derive macros like Hash can work too?

@mcitem
Copy link
Contributor Author

mcitem commented Jan 30, 2026

thank you. can you add a test case under tests, like https://github.com/SeaQL/sea-orm/blob/master/tests/derive_iden_tests.rs ?

we can call it derive_model_tests. we don't have to use the actual ts-rs crate, may be some built-in derive macros like Hash can work too?

Thanks for the suggestion! I have added the test case in tests/derive_model_tests.rs as requested.

Regarding the derive macros, I chose to use serde(rename_all = "...") for the following reasons:

Practical Validation: It effectively demonstrates that model_attrs and model_ex_attrs can correctly pass nested attributes to the generated structs, which is a primary use case for this feature.

No New Dependencies: Since serde and serde_json are already used in existing tests , this doesn't introduce any new external dependencies to the workspace.

Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very cool, thanks again!

@Huliiiiii Huliiiiii merged commit 8fb052f into SeaQL:master Jan 30, 2026
38 checks passed
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.

Applying custom derive macros to ModelEx

3 participants