Skip to content

Add prefix option to nested attribute in FromQueryResult and PartialModel#2989

Open
YouKnow-sys wants to merge 4 commits intoSeaQL:masterfrom
YouKnow-sys:nested-prefix-attribute
Open

Add prefix option to nested attribute in FromQueryResult and PartialModel#2989
YouKnow-sys wants to merge 4 commits intoSeaQL:masterfrom
YouKnow-sys:nested-prefix-attribute

Conversation

@YouKnow-sys
Copy link
Copy Markdown

@YouKnow-sys YouKnow-sys commented Mar 6, 2026

PR Info

New Features

  • add prefix option to nested attribute: #[sea_orm(nested(prefix = "..."))] for FromQueryResult and PartialModel derives.
  • compile-time error when multiple nested fields share the same type without distinct prefixes.

Bug Fixes

before this change having two nested model with same type will silently have unexpected behavior.

Breaking Changes

nothing, unless user depends on two field of same nested model have exactly same value... which is wrong behavior to begin with.

Changes

  • add get_list_args helper to GetMeta trait for parsing list-style attributes.
  • use syn::Error instead of custom Error enum in FromQueryResult derive for better error spans. (tbh we should do this for all other derive macros, but that's for another PR)

@YouKnow-sys YouKnow-sys force-pushed the nested-prefix-attribute branch from e2a85e4 to 8a7c868 Compare March 6, 2026 01:23
@YouKnow-sys YouKnow-sys force-pushed the nested-prefix-attribute branch from 8a7c868 to 0b67194 Compare March 6, 2026 01:40
@Huliiiiii Huliiiiii requested review from Expurple and tyt2y3 March 25, 2026 13:02
@Huliiiiii Huliiiiii self-assigned this Mar 25, 2026
Copy link
Copy Markdown
Member

@Expurple Expurple left a comment

Choose a reason for hiding this comment

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

Hi. Thank you for the PR

Comment on lines 748 to +752
/// #[sea_orm(nested)]
/// baker: Option<cakes_bakers::Model>,
/// // prefix is optional, useful when multiple fields share the same type
/// #[sea_orm(nested(prefix = "reviewer_"))]
/// reviewer: Option<cakes_bakers::Model>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add a codegen test for this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I added tests to partial_model, should I also add some test to the tests/partial_model_nested/nested_alias.rs and tests/from_query_result_tests.rs as well? seem unnecessary because the logic is clear, but if needed I can do it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Haha, I meant asserting the generated SQL query. Probably in a doctest. We have many examples of that in the codebase. Sorry for being unclear

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.

add prefix support to FromQueryResult nested attribute

3 participants