Skip to content

Commit

Permalink
Merge pull request #11 from kanko-travel/fix/join_alias_syntax
Browse files Browse the repository at this point in the history
fixed sql join alias syntax
  • Loading branch information
umran authored Aug 20, 2024
2 parents e595ae9 + 394ce11 commit 8b7aff3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions model/src/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 8b7aff3

Please sign in to comment.