sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

fix: allow LEFT JOIN to produce None for nested models

Open denyszhak opened this issue 3 weeks ago • 2 comments

PR Info

  • Closes #2617

Bug Fixes

When using LEFT JOIN with a nested Option<Model>, code tried to read the missing related row as if it were always present. This caused a type error instead of simply returning None.

This change makes nested optional models behave normal by treating all-null fields as a missing record.

Testing

Added test that validates the fix.

denyszhak avatar Dec 07 '25 14:12 denyszhak

the test case failed, any ideas?

thread 'from_query_result_left_join_with_optional_model_does_not_exist' (9460) panicked at tests/from_query_result_tests.rs:108:10:
succeeds to get the result: Type("A null value was encountered while decoding \"id\"")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

my current understanding: if the parent object is Option<Model>, then it effectively made all children fields Option<T>. but if a struct has 2 required fields, we can only construct a model if all 2 required fields are Some. is my understanding correct?

tyt2y3 avatar Dec 08 '25 13:12 tyt2y3

the test case failed, any ideas?

thread 'from_query_result_left_join_with_optional_model_does_not_exist' (9460) panicked at tests/from_query_result_tests.rs:108:10:
succeeds to get the result: Type("A null value was encountered while decoding \"id\"")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

my current understanding: if the parent object is Option<Model>, then it effectively made all children fields Option<T>. but if a struct has 2 required fields, we can only construct a model if all 2 required fields are Some. is my understanding correct?

Looking into this

denyszhak avatar Dec 09 '25 19:12 denyszhak