-
Hello, To avoid duplicated tables in the database or having redundant columns in the tables, I would like to know if it is possible to combine selectStmt := Foo.
SELECT(Foo.ID, Bar.ID).
FROM(
Foo.INNER_JOIN(Bar, Bar.RelationableID.EQ(Foo.ID),
Foo.INNER_JOIN(Bar, Bar.RelationableType.EQ("foo"),
).
WHERE xxx The target SQL I want to generate is this: SELECT foo.id, bar.id
FROM foo
INNER_JOIN bar on (bar.relationable_id = foo.id) AND (bar.relationable_type = 'foo')
WHERE xxx Is it possible? |
Beta Was this translation helpful? Give feedback.
Answered by
trevlt
Apr 3, 2025
Replies: 1 comment 1 reply
-
Do you mean AND in the join condition? Yes, of course: selectStmt := postgres.
SELECT(Foo.ID, Bar.ID).
FROM(
Foo.INNER_JOIN(Bar, Bar.RelationableID.EQ(Foo.ID).
AND(Bar.RelationableType.EQ(String("foo"))),
),
).
WHERE xxx |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
phlisg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you mean AND in the join condition? Yes, of course: