val e = quote {
querySchema[TestEntity]("test_entity", _.s -> "field_s", _.i -> "field_i")
}
val e2 = quote {
querySchema[TestEntity]("test_entity_2", _.s -> "field_s_2", _.i -> "field_i_2")
}
val q = quote {
e.union(e2)
}
Should produce:
SELECT x.field_s, x.field_i, x.l, x.o FROM ((SELECT x.field_s, x.field_i, x.l, x.o FROM test_entity x) UNION (SELECT x.field_s_2, x.field_i_2, x.l, x.o FROM test_entity_2 x)) AS x
Actually produces:
SELECT x.field_s, x.field_i, x.l, x.o FROM ((SELECT x.field_s, x.field_i, x.l, x.o FROM test_entity x) UNION (SELECT x.field_s, x.field_i, x.l, x.o FROM test_entity_2 x)) AS x
The inner unions always get the same aliases applied to their field as the outer query. This probably always correct for the left hand side but is not necessarily so for the right hand side.
You can even see this starting in the "expanded sql" trace (note that the aliases shown on the entity are ignored and are replaced by those of the parent query):
FlattenSqlQuery(
List(TableContext(Entity("test_entity_2", List(PropertyAlias(List("s"), "field_s_2"), PropertyAlias(List("i"), "field_i_2"))), "x")),
None,
None,
List(),
None,
None,
List(
SelectValue(Property(Ident("x"), "field_s"), None, false),
SelectValue(Property(Ident("x"), "field_i"), None, false),
SelectValue(Property(Ident("x"), "l"), None, false),
SelectValue(Property(Ident("x"), "o"), None, false)
),
false
)
Second example showing the same idea:
val e = quote {
querySchema[TestEntity]("test_entity", _.s -> "field_s", _.i -> "field_i")
}
val q = quote {
query[TestEntity].union(e2)
}
Should produce:
SELECT x.s, x.i, x.l, x.o FROM ((SELECT x.s, x.i, x.l, x.o FROM test_entity x) UNION (SELECT x.field_s, x.field_i, x.l, x.o FROM test_entity x)) AS x
Produces:
SELECT x.s, x.i, x.l, x.o FROM ((SELECT x.s, x.i, x.l, x.o FROM test_entity x) UNION (SELECT x.s, x.i, x.l, x.o FROM test_entity x)) AS x