From 394ce11004015caece10826654541412d6896ef4 Mon Sep 17 00:00:00 2001 From: Umran Hussain <1547890+umran@users.noreply.github.com> Date: Tue, 20 Aug 2024 02:37:01 -0700 Subject: [PATCH] fixed sql join alias syntax --- model/src/relation.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/model/src/relation.rs b/model/src/relation.rs index ee856bd..ce69ca1 100644 --- a/model/src/relation.rs +++ b/model/src/relation.rs @@ -80,50 +80,50 @@ impl RelationDef { match &self.reference { Reference::From(column) => { format!( - "LEFT JOIN {} ON {}.{} = {}.{} AS {}_{}", + "LEFT JOIN {} AS {}_{} ON {}.{} = {}.{}", related_table, parent, - column, related_table, - related_id_column, parent, - related_table + column, + related_table, + related_id_column ) } Reference::To(column) => { format!( - "LEFT JOIN {} ON {}.{} = {}.{} AS {}_{}", + "LEFT JOIN {} AS {}_{} ON {}.{} = {}.{}", + related_table, + parent, related_table, parent, parent_id_column, related_table, column, - parent, - related_table ) } Reference::Via((junction_table, from_reference, to_reference)) => { let join_junction = format!( - "LEFT JOIN {} ON {}.{} = {}.{} AS {}_{}", + "LEFT JOIN {} AS {}_{} ON {}.{} = {}.{}", + junction_table, + parent, junction_table, parent, parent_id_column, junction_table, from_reference, - parent, - junction_table ); let join_relation = format!( - "INNER JOIN {} ON {}_{}.{} = {}.{} AS {}_{}", + "INNER JOIN {} AS {}_{} ON {}_{}.{} = {}.{}", + related_table, + parent, related_table, parent, junction_table, to_reference, related_table, related_id_column, - parent, - related_table ); format!(