When using the join_on tag in bun ORM to specify join conditions for a relationship, the condition is unexpectedly influencing the WHERE clause, leading to a full omission of main entity results if the relationship's condition isn't met. This behavior is contrary to typical SQL JOIN operations where the main table's data would be returned with NULLs for the related table's columns if the JOIN condition fails.
Example
Given two tables books and authors, with a join_on condition like authors.nationality = 'Canadian' within the books model, the current implementation results in zero results for a book query when no authors meet the condition. The anticipated result is to receive the book data with NULLs for the author columns.
Expected Behavior
The join_on condition should be applied within the JOIN clause, permitting the retrieval of books records regardless of whether the authors condition is met.
Current Behavior
No books records are returned when the join_on condition for authors is not satisfied, suggesting that the condition is being incorrectly placed in the WHERE clause.
Steps to Reproduce
Define books and authors models with a join_on condition that references a field from the authors table.
Execute a query on books that includes a join with authors where the join_on condition (e.g., authors.nationality = 'Canadian') does not hold true.
Observe that the result set is empty, contrary to expectations.
Environment
bun ORM version: [v1.1.12]
Go version: [1.21]
Database and version: [postgres v15]
Additional Information
(Include logs, error messages, and any other context that might aid in diagnosing the issue.)
Suggested Resolution
If available, outline any potential solutions or workarounds you've considered or attempted.
Issue Description
When using the
join_on
tag in bun ORM to specify join conditions for a relationship, the condition is unexpectedly influencing theWHERE
clause, leading to a full omission of main entity results if the relationship's condition isn't met. This behavior is contrary to typical SQL JOIN operations where the main table's data would be returned with NULLs for the related table's columns if the JOIN condition fails.Example
Given two tables
books
andauthors
, with ajoin_on
condition likeauthors.nationality = 'Canadian'
within thebooks
model, the current implementation results in zero results for a book query when no authors meet the condition. The anticipated result is to receive the book data with NULLs for the author columns.Expected Behavior
The
join_on
condition should be applied within theJOIN
clause, permitting the retrieval ofbooks
records regardless of whether theauthors
condition is met.Current Behavior
No
books
records are returned when thejoin_on
condition forauthors
is not satisfied, suggesting that the condition is being incorrectly placed in theWHERE
clause.Steps to Reproduce
books
andauthors
models with ajoin_on
condition that references a field from theauthors
table.books
that includes a join withauthors
where thejoin_on
condition (e.g.,authors.nationality = 'Canadian'
) does not hold true.Environment
Additional Information
(Include logs, error messages, and any other context that might aid in diagnosing the issue.)
Suggested Resolution
If available, outline any potential solutions or workarounds you've considered or attempted.