Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: order by self-relation #3208

Merged
merged 2 commits into from Sep 21, 2022
Merged

fix: order by self-relation #3208

merged 2 commits into from Sep 21, 2022

Conversation

Weakky
Copy link
Member

@Weakky Weakky commented Sep 20, 2022

Overview

fixes prisma/prisma#12003
fixes prisma/prisma#9929
fixes prisma/prisma#10735

In the case of self-relation ordering, we weren't generating unique join aliases when hoping through multiple relations (of the same table) which was causing a SQL error (because the same aliased table was joined multiple times)

Comment on lines +240 to 243
let a_col = match previous_join {
Some(prev_join) => Column::from((prev_join.alias.to_owned(), a.db_name().to_owned())),
None => a.as_column(),
};
Copy link
Member Author

Choose a reason for hiding this comment

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

This ensures that if we do something like: { orderBy: { rel: { self_rel: { id: asc } } } }, the second join relies on the first one.

We used to make sure joins relied on each other slightly differently. This should be more bullet-proof.

Comment on lines +187 to +191
fn join_prefix(&mut self) -> String {
self.join_counter += 1;

format!("{}{}", ORDER_JOIN_PREFIX, self.join_counter)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I introduced shared state in the order by renderer to make sure we always generate unique join aliases.

@garrensmith garrensmith added this to the 4.4.0 milestone Sep 21, 2022
@Weakky Weakky merged commit f0b0274 into main Sep 21, 2022
@Weakky Weakky deleted the fix/order-by-self-rel branch September 21, 2022 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants